Weird physics behaviour when using setLinearVelocity()

Since I thought it would be easier in the long run to manage horizontal acceleration in code, I’m using setLinearVelocity() each frame to move the Player, this works as expected over a horizontal surface, but when I walk over a ramp the player goes flying skyward, and when it is about to touch the ground it slows down and covers the last units through small steps.
I want to know if this is a problem with my physics configuration or if I shouldn’t use setLinearVelocity() each frame and instead use physics acceleration, or maybe I should manage vertical acceleration via code as well instead of feeding getLinearVelocity().z for the Z axis velocity.
Would using KinematicBody help?
I’m using Bullet physics.
You can find the file below for testing, if you run it you’ll see a ramp to the right where you can check the behaviour I described.

Thanks for your time.

Here is the file:


In case you don’t use Google:
Mech.blend (860.8 KB)
And the sources content:
Player.hx (2.3 KB) Input.hx (1.3 KB) Scene.hx (231 Bytes)

HI @Quartz,

  1. Using setLinearVelocity() each frame to move the Player is the right way. One way to prevent the player from jumping when hitting the ramp is to push a part of the ramp below the “ground” plane. This will help smooth transition from “Ground” to “Ramp”

  2. The reason the player lands on the ground in steps is because of CCD. The CCD must be enabled only when the object is moving very fast. It is used to calculate collisions many times between each frame. However, this is not needed in your case. So, I suggest disabling the “CCD” option for the player object.

Best Regards,
QC

3 Likes

Thank you, I didn’t know CCD could cause that kind of problems, it seems it was also responsible for the jumping, since it didn’t happen after I deactivated it. Unfortunately, without It the Player can go through walls at it’s current speed, and increasing simulation steps doesn’t help, so I’ll have to design around that or find a solution.
I may use a different collider with CCD for lineal collisions and a ‘raiser’ attached to the bottom to lift the Player on inclines and steps.

Glad to help,

Are you sure that the player passes through other rigid bodies? This didn’t happen for me with the CCD disabled. I did not change any other physics settings.

1 Like

Yes, If I run directly towards a cube, the camera would clip in for a moment before bouncing our, If I run towards the corner of a cube It would go through, and if I run sideways into the ramp I could get trapped inside the mesh. Not sure why it only happens sideways, velocity is normalized.

1 Like