Hey everyone,
I’m new to JMonkey and newer even to the forums, so please forgive any naive mistakes I make. I’m trying to make a game where the player characters are controlled in an isometric perspective and rotate to look at the mouse cursor. I figured out the whole deal with mouse picking and used a ray to project the mouse’s coordinates onto the same y plane as my character, so that should all be working fine. My problem is with the actual rotation itself: as soon as I start trying to apply any sort of rotation in the update method (be it Quaternions or Matrix3f) my character slowly sinks through the floor. This happens even when I apply the empty-constructor Quaternion which I believe is supposed to add 0 rotation. Both the player and the floor are being represented by RigidBody boxes, and physics works perfectly when I don’t try to add rotation manually.
Am I making a silly mistake or does JMonkey physics usually choke when the programmer “takes control” of rotation each frame? I can probably turn off physics in my characters since the game doesn’t require gravity simulation or knockback or the like, so what little I do need can be done manually. But that’s a worst-case scenario.
Thanks!
Yes, the latter. If you set the location or rotation of the object each frame then you basically “beam” it in the “star trek” sense. So you cannot expect proper collision or anything anymore. Add to that you basically erase the physics computations results which makes computing them kind of futile and a waste of CPU cycles. A limited solution is the CharacterControl which allows you to set a basic walkdirection and lookdirection for your character. It has collision detection and allows for basic things like jumping etc. For more extended characters you can look at using kinematic rigidbodies that you move (see for example the quite extensive TestRagDollCharacter) but you have to care for the collision yourself. This can be done using physicsSpace.rayTest and .sweepTest, where the latter allows you to sweep for collisions with whole collision shapes to e.g. avoid collisions of the character while moving it (see TestSweep…blah :)). The “real physics” solution would be applying forces in the physics tick to your rigidbodies to have them counter the forces like a helicopter, boat or robot would but that requires extensive computations on the level of what the military does in their jets or honda with its walking robot ;).
Okay thanks for the reply! I think I’ll avoid the whole “jet fighters and walking robots” thing (for now) and check out kinematics.