Added velocity (bullet engine and JME3)

Hello everyone,

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?

Here’s how I move my space into the controller:

 @Override
    protected void controlUpdate(float updateInterval) {
        super.controlUpdate(updateInterval);

        if(this.isEnabled()) {
            this.spatial.move(velocity.mult(updateInterval));  <----- Here
            if((this.spatial.getLocalTranslation().subtract(startPosition)).length() >= distance){
                velocity.negateLocal();
                startPosition = this.spatial.getWorldTranslation().clone();
            }

        }
    }

Here’s how I add my two vectors in the character:

> @Override
>     public void prePhysicsTick(PhysicsSpace space, float tpf) {
>         ......
           .......
>         this.setLinearVelocity(velocity.add(velocityPlatforme));
>         .......     
           .......
>     }

Thanks
Thoced

Shouldn’t this be like an emergent properly of a high friction coefficient? At least that’s generally how it works in real life physics…

So I guess setFriction(something) should solve it.

Unfortunately, the friction has no influence because the platform is a RigidBody in Kinematic mode.

Can you please try with following settings.

setKinematicSpatial to false

and change this :

to

Vector3f currentLoc = spatial.getWorldTranslation();
Vector3f newLoc = currentLoc.add(velocity.mult(updateInterval));
spatial.getControl(RigidBodyControl.class).setPhysicsLocation(newLoc);

This should update platform spatial position in sync with physic tick, i guess.

I think I have already tried this, but I do your test again tonight (Belgian time). I will post the result. Thank you. Thoced

It’s not supposed to influcence the platform, but the cube. Is the cube kinematic as well? Why are you using physics then?

Edit: Indeed it should in fact, work this way.

A simple test showed that friction works well for RigidbodyControl but not for CharacterControl or BetterCharacterControl.

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.

I guess that is the predicted behavior for character controls

This seems to be a common problem. Shouldn’t there be an internal solution for this in Bullet engine !?

Well thats kind of the point - it’s not “internal” because its something you do differently from game to game.

Hello

I made the changes, my problem is solved in part.

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.

Thanks for your help.

1 Like

Do you mean vibrate wildly or does it actually move in up and down jump motion?

Sorry to answer so late

The body really jumps without stopping
As if he is bouncing