First I would like to say Hello to everyone. I am new to this Forum, and relatively new to Unity. I hope to find the solution to my problem which has given me quite some headache. I am trying to make a 3D space shooter. The flying object is supposed to orientate itself by using the transform.LookAt
function and accelerate using the rigidbody.AddRelativeForce
. For now I have the camera following the Vessel by simply parenting it to it. It works great only that the movement is a bit jerky at times, it lags mostly noticeable when turning. (the script is attached to the Vessel)
function Update()
{
var scr2world: Ray;
scr2world = Camera.main.ScreenPointToRay(Input.mousePosition);
var vel = transform.position + transform.forward*4;
var focus = Vector3.MoveTowards(vel,scr2world.GetPoint(80),Time.deltaTime * 10);
transform.LookAt(focus);
Debug.DrawRay(scr2world.origin,scr2world.direction*50,Color.yellow);
Debug.DrawLine(transform.localPosition,scr2world.GetPoint(80),Color.red);
Debug.DrawLine(transform.localPosition,focus,Color.black);
}
The Rays and Lines I drew to verify the coordinates. I expect the black line to align itself with the red. It does but when I comment out transform.LookAt(focus);
it remains at Vector3(vel)
and vibrates. I have tired Lerp,Slerp,MoveTowards,smoothDamp. But ran into the same problems or others. Is my methode wrong to achieve the desired motion? Or is my code missing something? Is the jerky motion generated by the Vessles motion or the cameras motion?