Player moving up a staircase

Hello,

I am using the First Person Template to control my character. I would like to make my character move up a stair case. Does anybody know how to implement such thing?
For example: You can see in the picture below, I would like the player to automatically shift up to the second platform when controlling the player with the “WSAD” keys.

Any help would be very much appreciated.

Thank you!

Hi @dongqtm,

For the default Player controller that uses the capsule collider shape, you can automatically shift up on objects up to a certain height (which corresponds to the lower part of the capsule).

To climb this up:

  • If you have a small level and control of your geometry add invisible ramps.
  • Raycast forward, let’s say 1 unit, starting at the height of the character’s feet (e.g. 0.125 of the total height) to detect possible steps. If a collider is detected push your character up.
1 Like

Ahhh I see. Is there a way for me to increase that lower part of the capsule to adjust the minimum height where I can automatically shift up on?
Also just curious for the Raycast forward method. It would work in the case if the character is moving forward onto the object. What would happen if the character is moving backward to the object, or at an angle to the object, would the raycast forward method still work?

Thank you so much for your help so far!

Those collision shapes are internal shapes used by Ammo.js, I think you can’t change these since are part of the optimizations the physics simulation does.

For raycasting yes, to handle strafing or moving backwards and being able to shift up stairs you will have to start doing multiple raycasts.

2 Likes

I see. Awesome! Thank you for your help Leonidas!

1 Like

Keep in mind, @dongqtm, that you can also provide your own mesh to be used for collision detection. If you need the cylinder to have different shape features, you can create one in a 3D modelling software (e.g. belnder or clara.io) and import to Playcanvas. Then, in the collision property, instead of selected Cylinder pick Mesh and point to your imported model.
image
Try to keep your polygon count low. This mesh will not be visible, so it doesn’t need to be pretty. Convex shapes are better.

2 Likes

I’d say if you go that way, definitely opt to use compound colliders instead of mesh collider. There are no mesh to mesh collision supported right now in Ammo.js, so your character controller won’t be able to interact with those bodies.

2 Likes

That’s a good idea LeXXik! But yeah I will consider using compound colliders instead, seem like it is better for the long term.

Thanks guys!

2 Likes