In my game, I move platforms. These platforms have a RigidBodyControl attached in Kinematic mode. I am also attaching a second control that takes care of moving the space.
When a character is on the platform, he must accompany it.
To do this, I thought to apply the velocity of the platform to my character.
To know when my character is on the platform, I capture the collision with the implementation of the PhysicsCollisionListener listener.
The character accompanies the platform in movement, only here is my problem:
Although the velocity vector is added to the motion vector (everything is passed to the setLinearVelocity method). The character is either a little too fast or a little too slowly depending on the number of frames per second.
here is a video of the problem:
I think the problem comes from the difference in refresh between the Bullet engine and the frame rate per second of the JME3 controller’s update method, but I can not understand how I could fix that.
What do you think should be changed or configured?
That sounds like a problem with the character controls. Then again I guess the result may be too jittery for the camera without some unphysical hacking.
First of all I have to tell you that I did not use BetterCharacteControl but a custom class derived from RigidBodyControl.
I was inspired by the code BetterCharacterControl but did not use it because each time I use it, my character seems to jump constantly. So I decided to make a custom class.
To go back to my platform problem, my first problem was that I did not consider the resulting velocity. Let me explain.
I initialized with each frame, the x and z fields of the velocity vector at 0. (I kept the y for gravity). I did not take into account the velocity results due to friction.
Now my character moves at the same time as the platform, I do not need to manually add the velocity of the platform, all done alone.
Only now, I have another problem.
I must add, at this velocity, a direction vector (walkdirection). As this vector is added to each frame, the velocity increases almost exponentially.
I have to find a way to cap velocity.
I try to get inspired by the code of BetterCharacterControl.