I am making a space shooter and the Vessels orientation is driven by a LookAt function and its acceleration with rigidbody.AddRelativeForce(from another script). All works great the Vessel flys smoothly and for forces on the rigidbody are calculated. Only Problem I have is when I look towards Vector3.up or Vector3.down then the Vessel starts to spin. My goal is to have it so I can fly Loopings. (The script is attached to the vessel and the camera a child of the vessel)
function FixedUpdate()
{
var camTransform = Camera.main.transform;
//Mouse on Screen Coordinates to World Ray
scr2world = Camera.main.ScreenPointToRay(Input.mousePosition);
//Moves Focus to Point on Ray
var vel = transform.position + transform.forward*4;
var focus = Vector3.MoveTowards(vel,scr2world.GetPoint(50),0.2);
transform.LookAt(focus); //Vessel looks at Focus
//Rays and Line for verification of coordinates
Debug.DrawRay(scr2world.origin,scr2world.direction*100,Color.yellow);
Debug.DrawLine(transform.localPosition,scr2world.GetPoint(100),Color.red);
Debug.DrawLine(transform.localPosition,focus,Color.grey);
}
I believe that the LookAt functions affects only the rotation on the Y and X axis, and the Z axis is not really driven directly by anything. What can I change to be able to fly Loops? Is that a common restriction when using LookAt? I have tried to set the localRotation to 0 or to clamp it, with poor results.