JME Simple Examples Project

What?



Physics is correct now.



I know there coul be a variant without physics. But that’s for another example.

@mifth said:
What?

Physics is correct now.

I know there coul be a variant without physics. But that's for another example.

a) everything
b) nope
c) more confusing and erroneous examples outside our site, nice!

And what is wrong in physics? I did everything as you told me. PreTickListener, ApplyForces… So what’s wrong?

You set the rotation.

Ok i get you. What should I use instead of setPhysicsRotation() method?



Other words how can I force the physical rotation?

You apply torque. http://hub.jmonkeyengine.org/javadoc/com/jme3/bullet/objects/PhysicsRigidBody.html#applyTorque(com.jme3.math.Vector3f)

1 Like

OMG!!! That’s will be very complex math. I will need to use 3 times applyTorque() for X,Y,Z axes. Ahhh… I’ll die with this math.

Is it just me or is the applyTorque javadoc incredibly vague? I’ve just read it and I still have no idea what it means. It seems additionally weird as I’d expect at the least an axis of rotation + force strength…potentially even axis, momentum, and strength although you could pre-multiply those two.

@zarch said:
Is it just me or is the applyTorque javadoc incredibly vague? I've just read it and I still have no idea what it means. It seems additionally weird as I'd expect at the least an axis of rotation + force strength...potentially even axis, momentum, and strength although you could pre-multiply those two.

The vector has three axes it can operate in? The length in each direction gives the impulse strength.

The impulse strength on what? It’s a rotational force so clearly not at the centre of the object.



I guess maybe one of the unit vectors, but which one?

@zarch said:
The impulse strength on what? It's a rotational force so clearly not at the centre of the object.

I guess maybe one of the unit vectors, but which one?

Why clearly not at the center of mass? It is the rotation force at the center of mass unless you specify an offset from it.
Rotation around X axis: Vector3f(1,0,0); Counter rotation around X: Vector3f(-1,0,0); Rotation around both X and Y: new Vector3f(1,1,0);

So the vector isn’t being used as a vector at all (in the traditional sense) but as a way to store rotational forces around the x, y and z axes?

Yes

If someone is able to convert setPhysicsRotation() to applyTorque(), so it will be very appreciated. I’m not good in math. @wezrule , possibly you can help? As you did tutorials with Math.

They are fundamentally different things mifth.



Applying torque is applying a rotational acceleration, setPhysicsRotation is setting a rotational value.



You need to look at which way the ship is pointing now, which way you want it to point, and then apply torque in the correct direction, remembering to decelerate as well as accelerate.



If it was directly player controlled that would be easy as you just apply a fixed torque to each keypress (*tpf).

Ok, @zarch possibly you can give a tip. For example i have:



[java]

Vector3f camPos = new Vector3f(17.32f, 10.0f, 0.0f);

Quaternion camRot = new Quaternion(0.18f, -0.68f, 0.18f, 0.68f);



Vector3f shipPos = new Vector3f(-16.30f, 3.03f, -11.17f);

Quaternion shipRot = new Quaternion(0.06f, 0.46f, -0.03f, 0.88f);

[/java]



What should be the vector to applyForce()? As far as I understand there should be 3 forces. applyForce(X), applyForce(Y), applyForce(Z).

Ok, bear in mind I’ve never used any of this stuff. I’m just going off my brief conversation with normen above…



You need to look at camRot and shipRot and work out the acceleration around the x, y and z axes needed.



You then create a vector3f with those accelerations and applyTorque with that vector.



The three forces are the three components of the vector.





Working out the accelerations is not trivial and I don’t have time right now, having the ship manually controlled will be MUCH simpler so if you can’t do the math for automatic then go to manual. Just change things to use wasdqe as pitch, roll, yaw or similar.



so

A applies a torque around the z axis - so (applyTorque(Vector3f.Unit_Z.mult(-tpf))

D applies a torque around the z axis - so (applyTorque(Vector3f.Unit_Z.mult(tpf))

W applies a torque around the x axis - so (applyTorque(Vector3f.Unit_X.mult(-tpf))

S applies a torque around the x axis - so (applyTorque(Vector3f.Unit_X.mult(tpf))



To support two buttons at once you can either merge the vector and applyTorque once or applyTorque multiple times. The merging approach would probably be better though.



etc.

@zarch , we misunderstood a bit each other. I don’t need to rotate with WASD. WASD is acceleration only. I need the ship rotation to be as camera rotation ALWAYS. In other words i need:



[java]

ship.setLocalRotation(cam.getLocalRotation());

[/java]



So ship’s rotation to be with camera always.

Then you need to take the ships rotation out of the physics stuff entirely…which I’ve no idea if its even possible.



Physics is all forces and momentum, that’s completely different from what you are doing.

1 Like
@zarch said:
Ok, bear in mind I've never used any of this stuff. I'm just going off my brief conversation with normen above...

You need to look at camRot and shipRot and work out the acceleration around the x, y and z axes needed.

You then create a vector3f with those accelerations and applyTorque with that vector.

The three forces are the three components of the vector.


Working out the accelerations is not trivial and I don't have time right now, having the ship manually controlled will be MUCH simpler so if you can't do the math for automatic then go to manual. Just change things to use wasdqe as pitch, roll, yaw or similar.

so
A applies a torque around the z axis - so (applyTorque(Vector3f.Unit_Z.mult(-tpf))
D applies a torque around the z axis - so (applyTorque(Vector3f.Unit_Z.mult(tpf))
W applies a torque around the x axis - so (applyTorque(Vector3f.Unit_X.mult(-tpf))
S applies a torque around the x axis - so (applyTorque(Vector3f.Unit_X.mult(tpf))

To support two buttons at once you can either merge the vector and applyTorque once or applyTorque multiple times. The merging approach would probably be better though.

etc.


As an additional note: forces in bullet (it seems) are always using world-axis and not object space, I struggled with that for weeks since I suck at math :)
Mifth, physics is trying very hard to be accurate physics, so in effect what you must do is actual rocket science for your space ship :) It just isn't that easy to have things bouncing of each other and at the same time controlled by the player. It is a very hard problem.
Even character control is a type of hack in Bullet, it tries to do both of those by striking a compromise about what the player controls (walking direction) and the physics of standing on solid ground and jumping.