- Home /
Does setting the rotation of an object override the physics engine?
If I control a spaceship by changing its rotation directly, will that override any change the physics engine would have done? For instance, let's say my ship hits an asteroid, and the physics engine calculates that the front end should be knocked upwards. Would using a control scheme that sets the rotation directly allow the player to negate the torque by engaging the controls in any direction at time of impact?
Answer by Piflik · May 11, 2012 at 07:09 PM
Yes.
You would have to use rigidbody.AddTorque or rigidbody.AddRelativeTorque.
Ok then. Would you know how to prevent this issue?
www.youtube.com/watch?v=NZQ4X1YL1Vo
The ship isn't turning on its axis properly. I've tried both of the following with identical results:
gameObject.rigidbody.AddRelativeTorque(Vector3.up*$$anonymous$$chYaw*modifier);
and
gameObject.rigidbody.AddForceAtPosition(-gameObject.transform.right*($$anonymous$$chYaw*modifier),gameObject.transform.position-(gameObject.transform.forward*4)); gameObject.rigidbody.AddForceAtPosition(gameObject.transform.right*($$anonymous$$chYaw*modifier),gameObject.transform.position+(gameObject.transform.forward*4));
The issue only arises when the ship is asymmetrical when viewed in profile relative to the axis of rotation. For instance, the ship in the video pitches up and down just fine. But I can also make a ship that yaws fine, but pitches weird, all based on the symmetry of the colliders that make up the ship. Also, note that I apply the thrusts to the center of gravity (or rather, move the children relative to the top object so that the objects position will be identical to the center of gravity).
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Composite body physics 2 Answers
Should I control npcs with Rigidbodies or with the CharacterController? 1 Answer
F-Zero Game - Collisions/Physics. 1 Answer
How do I get an asymmetrical spaceship to rotate correctly using torque? 1 Answer