I have a problem with rotation that I was hoping someone could point me in the right direction.
I am sure there is a much easier way to ask the question, but here is the long version.
I have a script (below) which controls an object in 3D space. I want to emulate zero gravity.
The problem I am having is that when the object is heading “north” and pitched downwards, when I rotate “south” the object rotates on it’s own Y axis rather than the world axis which results in the object pitching up when heading “south”.
Is there a simple way to cause “Horizontal” input to rotate an object using the world axis?
Thanks for any advice.
-ab
var speed : int = 10;
var gravity : int = 10;
private var moveDirection = Vector3.zero;
function FixedUpdate () {
var controller :CharacterController = GetComponent(CharacterController);
moveDirection = Vector3(0,0, Input.GetAxis("Vertical") * speed);
moveDirection = transform.TransformDirection(moveDirection);
var rotateY = (Input.GetAxis("Horizontal") * 200) * Time.deltaTime;
var rotateX = (Input.GetAxis("Mouse Y") * -400) * Time.deltaTime;
controller.transform.Rotate(rotateX,rotateY, 0);
controller.Move (moveDirection * Time.deltaTime);
}