Bullet and forces, the force seems not to be with me

Hello, i currently try to make a hovering object,

stage 1 is to make it completely hovering, aka staying on it’s position



I am initialing my unit trough:



[java]

CollisionShape unitShape=CollisionShapeFactory.createDynamicMeshShape(unit);

Control unitControl=new RigidBodyControl(unitShape,2000);

unit.addControl(unitControl);

this.physicsSpace.add(unitControl);

[/java]



and then in the preTick i do:

[java]

public void prePhysicsTick(PhysicsSpace space, float tpf) {

JetPhysicsData jetphysicsData = ((JetPhysicsData) e.getEntityData(JetPhysicsData.class));

if (jetphysicsData != null) {

jetphysicsData.getControl().applyCentralForce(jetphysicsData.getControl().getLinearVelocity().negate().mult(jetphysicsData.getControl().getMass()));

}

[/java]



Debugshapes looks good, and if i clearForces() on each preTick the unit stays in the air. But how do i calculate the amount of force needed to keep the object in the air?

assuming you haven’t touched gravity. Then

[java]jetphysicsData.getControl().applyImpulse(new Vector3f(0, 2000*9.81f * tpf, 0), Vector3f.ZERO);[/java] should do it

1 Like

using a linearfactor in the dampeing will also greatly help to stabilize objects

1 Like

Thank you both,



Seems applyInpulse did the trick. Is there a somewhere an extended tutorial about physics?

For example, why does applyImpulse work, but applyCentralForce not? Maybe my physicskills lack too, but applying a force and an impulse should probably result in the same movement, beside a force should not need an update at each tick

force*mass = impulse if i remmeber right.

Based on some guesswork (so please correct if wrong). impulse = force * time

Bullet clears the forces each tick (which I think is weird but there you are). So in effect there is no difference except scale between force and impulse. That is, impulse is defined in seconds and force is applied for each tick. So assuming that bullet runs at 60 fps it would be (not the same but lead to the same effect) of applying a (force/60) for 60 ticks = impulse.

wezrules calculation works because it is uses the metric system (i.e. 9.81 is m/s*s) and thus uses impulse.



I think :slight_smile:

2 Likes
@jmaasing said:
because it is uses the metric system (i.e. 9.81 is m/s*s)


What other system should be used in a modern system ;)



Hm well with the impulse calculation i am able to keep the jet up in the air, but using force would probably be better since less updated are required.. Yet i was able to calculate the needed force..
3 Likes

Do not worry about the forces and performance to much. 50% is collision detection 50% is collision solving. The forces are in the rounding errors.

zzuegg said:
What other system should be used in a modern system ;)

Hm well with the impulse calculation i am able to keep the jet up in the air, but using force would probably be better since less updated are required.. Yet i was able to calculate the needed force..


Yeah, that picture says it all :)

But you mean continuous force? I think I saw some forum where Erwin (of Bullet) suggested setting gravity for the object for that since Bullet forces are cleared every tick.

I'm trying to make a hovercraft, first using the vehicle control but that falls through the terrain in weird circumstances, then using forces on rigid bodies but that was sooo hard to keep the vehicle stable (mostly because it started rotating whenever I hit a corner and clamping the torque was not easy). Then a lot of configurations with joints and invisible frictionless boxes that was exceedingly arcane.
Now I'm doing a kinematic body and just setting the height and rotation I want. Much better game feeling but I'm fighting to simulate collisions with the environment which seems silly when I have bullet physics.
If only it was easy to make vehicle games :)
@jmaasing said:
Yeah, that picture says it all :)

But you mean continuous force? I think I saw some forum where Erwin (of Bullet) suggested setting gravity for the object for that since Bullet forces are cleared every tick.

I'm trying to make a hovercraft, first using the vehicle control but that falls through the terrain in weird circumstances, then using forces on rigid bodies but that was sooo hard to keep the vehicle stable (mostly because it started rotating whenever I hit a corner and clamping the torque was not easy). Then a lot of configurations with joints and invisible frictionless boxes that was exceedingly arcane.
Now I'm doing a kinematic body and just setting the height and rotation I want. Much better game feeling but I'm fighting to simulate collisions with the environment which seems silly when I have bullet physics.
If only it was easy to make vehicle games :)


In my case, the jet explodes anyway when there is a collision so that might not be my problem.. But yeah, i am also thinking about using kinematic for simplicity..

But first i want to try using real physics..

Well it is definitly possible to have hovering objects with forces



Thats how I do it, i doe three raytraces to determine distances, and then apply forces based on their location. Thogehther with some kinda heavy angular and linear dampening it feels kinda real.



https://aurora42.de/jamwiki-1.2/uploads/en/2012/6/hovertank_vegetation-17005932.png

That’s a great inspiration knowing that you got it working :slight_smile: I used ray casts also but found it hard to balance the forces (especially the angular dampening and turning). I’ll revisit my code. Thanks!

I am definately going to try it, but it still feels overshooted for a RTS

Its’s a try and error process mostly XD, but once you are near the balance the finetuning is a bit simpler