Mini Project: Pac Man

In this project, you will create a simplified recreation of the famous game of Pac Man in 3D. You will make the character to play as him and make 2 scripts. One to make the player controlling Pac Man do the "Waka Waka" sound when moving and the other a pellet to collect in the world when playing.

Topics:

  • Parts
  • Material
  • BrickColor
  • Scripting

Setting up the Project

A pellet a day keeps the ghosts away

  1. Get 1 wedge and 2 spheres
  2. Add BrickColor and Material
  3. Make one sphere slightly smaller and rename it to
    HumanoidRootPart
    , the wedge to
    Mouth
    and the other sphere to
    Head
  4. Place the
    Mouth
    in a way it will cut out from the
    Head
    to make it look like Pac Man. Don't use the small sphere yet.
    • Hint: Turn off collisions so you can move the
      Mouth
      inside the
      Head
      .

  5. Select the
    Mouth
    and make it a negative part by selecting the option from "Model" and "Negate" (red in image)
  6. Then select both the
    Head
    and
    Mouth
    . Click on the "Union" option (red in image). Make sure you rename the new
    Union
    to
    Head
    .
  7. Now place the
    HumanoidRootPart
    roughly in the center of the
    Head
    and make it transparent.
  8. Select both parts and group them using "Ctrl + G" and rename the "Model" to
    StarterCharacter
    . Note: This rename is important to be able to play as this object.
  9. Add a "WeldConstraint"
  10. Connect the
    Head
    to the
    HumanoidRootPart
    by changing the "WeldConstraint" Part0 and Part1 to them respectively (red in image)
  11. Add a "Humanoid" to the "StarterCharacter" and change its "HipHeight" property to 1. Note: "HipHeight" changes how far the
    HumanoidRootPart
    is from the floor by studs, you can make it a bigger number if necessary.
  12. Place the
    StarterCharacter
    in the "StarterPlayer" folder and click play!

The Scripts

Script some pellets! Add a small sphere, rename it to

Pellet
, anchor it, turn off its collission and make it Neon.

Add a script inside the

Pellet
, rename it to
PelletScript
and add the following code:

In this script, we start by adding a function that is only activated when something touches the Parent object (pellet). It then checks it is a Humanoid (which players have). If it is a Humanoid it makes it invisible and untouchable to allow it enough time to play the pellet collection sound before destroying the entire object.

Inside the

PelletScript
add a "Sound" object and rename it to
Eat
(red in image). Then add the following into the SoundId property: rbxassetid://4797903038 (blue in image)

Now you can clone it and touch them to eat them!

Now, we will script Pac Man to make sounds! We will be adding some code to have Pac Man make the famous "Waka Waka" sound when walking. Add a Local Script object on the "StarterPlayer" folder and rename it to

WalkingSound
(red in image)

Add the following code:

In this script, we access the characters "Running" feature in order to change its properties. One of these properties is the sound made by the character when walking. As such we change the SoundId to the "Waka Waka" sound by getting the ID from one in toolbox.

Congratulations! You will now make the famous "Waka Waka" sound when playing as Pac Man!

Follow Up

  1. Decorate the world!