- Home /
How to change rotation through script
I want to know how to change an object's rotation on specific axis through script when it touches the ground because I am working on a flight sim. I know how to chage the rotation of it but I don't know how to change rotation for only the X and Z axis but keep the rotation of the Y axis the same. I use this code.
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.name == "Terrain"){ transform.rotation = Quaternion.Euler(0,0,0); } }
Answer by whydoidoit · Jul 04, 2012 at 03:41 AM
Use something like this:
var rotationVector = transform.rotation.eulerAngles;
rotationVector.z = 0;
transform.rotation = Quaternion.Euler(rotationVector);
Answer by xKroniK13x · Jul 04, 2012 at 05:18 AM
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.name == "Terrain"){ transform.rotation = Quaternion.Euler(X,Y,Z); } }
Alternatively, if it is a rigidbody, you can lock certain rotations on the rigidbody settings of the object.
Your answer
Follow this Question
Related Questions
Make ball flip around cube... 0 Answers
Object won't rotate z axis on second click? 2 Answers
How to change 'vertical' and 'horizontal' axis when rotating the object 0 Answers
Need help with rotation script. 1 Answer
just a simple question.. 1 Answer