Best Approach for Player Movement in a Runner Game with Lane Shifting

Hey everyone,

I’m working on a runner game featuring three lanes where the player needs to shift lanes and dodge obstacles. Currently, the platform is moving smoothly. I’ve successfully implemented a player jump with animation, using applyImpulse().

Now, for shifting the player to different lanes, I initially considered using applyImpulse() and stopping it by setting linear velocity to zero upon collision with the lane collider. However, I’m concerned this approach might not provide the desired output, especially considering the chance of the player position being slightly off in the center lane.

I’m contemplating changing the player from dynamic to kinematic, but I’m unsure about the best way to handle player movement in this kind of game. Any suggestions or insights would be greatly appreciated!

Hi @Kaverappa!

You can use teleport(), but this will happen instantly without transition.

Yeah, I’m considering handling everything using position methods like translate or setLocalPosition() for full control over speed and positioning. Could you guide me to resources that demonstrate jump and side movement using code? Also, should I opt for a kinematic rigid body since I need to check if the player collides with objects?

If you want that the player is for example bounching back after colliding then it’s maybe better to keep the rigidbody dynamic. If you only need to restart the game or something, then you can use a kinematic rigidbody as well.

To create a jump function with a kinematic rigidbody you need to do something like translateLocal() upwards and forwards for a small time and after that you need to do it downwards and forwards.

1 Like

Can kinematic detect collision like dynamic or should I use trigger method?

A kinematic rigidbody can detect collision with the collisionstart event, but will not respond to it by themself until you program something by script.

I think I can work with this by adding some animation or something. Thanks a lot for the help.

1 Like

Yes indeed, you can activate an animation on collision using the collisionstart event. :+1:

1 Like