Run and Jump Mechanic

I can’t figure out how to add a jump amd run mechanic to my potential game….

Hi @MaxSanta,

The quickest way is to start from the first-person controller script that ships with the engine. It handles walking, running and jumping, with keyboard and mouse, touch and gamepad input. You can try it in the First Person example.

To add it to an Editor project:

  1. Open the Scene Settings panel, expand PHYSICS and click IMPORT AMMO. The controller is physics-based, so it needs this.
  2. In the Assets panel, create a new script called first-person-controller.mjs and replace its contents with this file.
  3. Create an entity called Player and place it a little above your floor. Add a Script component to it and add the firstPersonController script.
  4. Make your Camera a child of Player, set its position to 0, 0.5, 0, and drag it into the script’s Camera attribute.
  5. Give your floor and walls a Collision component sized to fit them and a Rigid Body set to Static, so the player has something to stand on.

The script adds a capsule collision shape and a dynamic rigid body to the player for you. When you Launch, click to capture the mouse, then use WASD to move, Shift to run and Space to jump. You can tune Ground Speed, Sprint Multiplier and Jump Force in the script’s attributes.

If you’d rather have a camera that follows a character from behind, there’s also a third-person controller, shown in the Third Person example.

If you get stuck, post a link to your project and we’ll take a look.