Just mucking around with unity trying to aim a space ship:
var pointDistance : float = 50.0;
var turnSpeed : float = 3.0;
function LateUpdate(){
var targetPos : Vector3 = Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,pointDistance));
var rotation = Quaternion.LookRotation(targetPos - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * turnSpeed);
}
It works pretty good, except of course when you start pointing towards world up or world down where it gets a bit spastic.
Just was wondering how you avoid this problem - so that the ship can do loop the loops etc.
I’m thinking that it’s a problem with Quaternion.LookRotation and its world direction. I’m hoping there is a quicker way of solving this than writing my own lookrotation algorithm.
Thanks for your time.