Physics only really applying forces on debug mode

I am facing an odd issue with bullet that I am not sure what is the cause.
Odd is that it was working nicely until I separate the game run state in an separated appstate…
I am applying force to an object in the physicstick, I can see in the java debug the forces are being applied, but the object don’t moves. other forces like collisions are working fine. When I activate the debug it moves…
Currently my game have several appstates, but only one bulletstate declared in the main class, maybe this is the problem ?
If so, how to fixed ? Should I declare new bulletstates for each appstate ?
Maybe there is another cause ?

I just found out something funy …
If I enable the v-sync, it works … How come ?
Also, I remember a few days ago I change some configuration in the video card.
Is that possible the video configuration and video frame rate to compromise the bullet behavior ?

Absolutely not. 100% not.

I don’t know what your problem is but it isn’t that.

Thanks pspeed, I just want to confirm it.
Currently its working ok with the vsync, I dont know why when I disable it bugs the jbullet in my case.
Should I try to change the bullet parallelism or something like that ?
The game is running in 40 or 60 fps (depending on the vsync) very smoothly so its not because low fps its getting this.

Also, I have an doubt about the bullet.
If I want to remove all bullet objects ( clean up ), is that correct to do this ? :

    Main.bulletAppState.getPhysicsSpace().destroy();
    Main.bulletAppState.getPhysicsSpace().create();

What FPS do you get when you run without vsync? Maybe it is so high that you run into floating-point errors with the TPF.

arround 110 …
I did notice that if I decrease the mass from the objects I can see they moving a bit.
There is any way to check the “fps” from the bullet thread ?

…that sounds like some “force” or “impulse” you are applying is somehow supposed to have inverse tpf factored into it but doesn’t. Or you are adding tpf where you shouldn’t be.

That is my physics tick :

 public void physicsTick(PhysicsSpace space, float tpf) {
        float distance = objNode.getWorldTranslation().distance( playerShip.getWorldTranslation());
        Vector3f directionToPlayer = playerShip.getWorldTranslation().mult(distance);
        spatialBody.applyForce(directionToPlayer, spatial.getWorldTranslation()); //applyCentralForce(directionToPlayer);

        Vector3f velocity = spatialBody.getLinearVelocity();
        if( velocity.length()>maxVelocity ) velocity = velocity.normalize().mult(maxVelocity);
        spatialBody.setLinearVelocity(velocity);
   }

I tried to commend the last 3 lines but had the same results.

I am feeling that this have something do to with it :

    Main.bulletAppState.getPhysicsSpace().destroy();
    Main.bulletAppState.getPhysicsSpace().create();

There is other way to clean all physic objects ?

You can keep a list of them and simply call physicsSpace.remove(obj)

There is a way to do it :

Iterator itrRB = s.getRigidBodyList().iterator(); while(itrRB.hasNext()) { s.remove( (RigidBodyControl)itrRB.next() ); }
Unfurtunally it dosent work with joints, but it was not hard to interate all joints and remove it.

About my problem, after I downsized the mass of the objects they are working now, but I am not sure how precise it is because I am not using tpf.
@pspeed said tpf should never be used to correct forces right ? But I did notice the physicstick has an tpf, probally from the bullet, so it could be used to correct problems in the behavior of bullet when the fps changes I guess, or I am mistaken ?

I have no idea what bullet does and have never used it or looked at the source (you could though). I’m just saying that based on the symptoms it seemed like something was having tpf factored in that shouldn’t be or something needed /tpf factored in.

It just depends on how bullet is using the value internally and I’ve learned not to second-guess it’s name for things.

No worries ! :smile:
Thanks to clarify it.
I will play a bit with the bullet tpf, I guess its just a case to add proportional forces (tpf<60 %) to the forces I am using and it will fix this issue.

Would probably save you a lot of time just to look in the bullet sources to see what it’s doing with the values you set.

Either you need a * tpf or a /tpf somewhere if you are getting frame dependent behavior.

I mean, the general physics equations aren’t hard:
vel = vel + accel * tpf;
pos = pos + vel * tpf;

…so if something you are passing ends up with the wrong value in whatever bullet is going then you can back track and figure out what you should be passing.

Or it’s a mass problem… knowing the bullet equations and where which values are injected would be useful to you.

Will do it ! Tx again !

I know this topic is already a bit old, but I could not fix it yet.
I made this works puting the vsync at 40 and made the jbullet tick at 60, but now I need a bit more performance and I need to decrease the jbullet tick to 40, and increase the normal fps to 60.
When I do that, the objects moved by forces simple dosent move anymore…
They just move when the games lags a bit into less then 40 fps.

Some code :

private float maxVelocity = 2f;

private void createPhysics() {
    SphereCollisionShape collisionShape = new SphereCollisionShape( ratius );

    // Create the joint
    RigidBodyControl rigidbox = new RigidBodyControl(new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)), 0);
    rigidbox.setPhysicsLocation( initialRotationNode.getLocalTranslation() );
    initialRotationNode.addControl(rigidbox);
    SixDofJoint thisjoint = Utils.createFreeJointSixDof(initialRotationNode,objNode,collisionShape,3,AppStateGamePhaseRun.bulletAppState);
    AppStateGamePhaseRun.bulletAppState.getPhysicsSpace().add(thisjoint);
    spatialBody = (RigidBodyControl)thisjoint.getBodyB();
    Main.collisionsGroups.addObjectOnGroup(spatialBody, "enemy",new String[] {"pickable"}); // we want the bullet to colide with the shooter in this case

    // Enable tick listener
    AppStateGamePhaseRun.bulletAppState.getPhysicsSpace().addCollisionListener(this);
    AppStateGamePhaseRun.bulletAppState.getPhysicsSpace().getPhysicsSpace().addTickListener(this);
}

Physics tick :

public void physicsTick(PhysicsSpace space, float tpf) {
    float distance = objNode.getWorldTranslation().distance( targetNode.getWorldTranslation());
    Vector3f directionToPlayer = targetNode.getWorldTranslation().mult(distance);
    spatialBody.applyForce(directionToPlayer, spatial.getWorldTranslation()); //applyCentralForce(directionToPlayer);
    Vector3f velocity = spatialBody.getLinearVelocity();
    if( velocity.length()>maxVelocity ) velocity = velocity.normalize().mult(maxVelocity);
    spatialBody.setLinearVelocity(velocity);
}

I tried to mult the dicectionToPlayer vector, but dosent mather if I put 1 or 1000000, it simple dont move, so I could not find a way to fix it using the tick fps…
Removing the setlinearvelocity line also dont make any effect…
I dont know what else to do, I could create an invisible physic object and make it colide into it to force it to move, but it seens stupid…