Hi, in your Scene, you should have your Ship as a GameObject, and another GameObject that will be the target, you need to attach a script, (name it “LookAtTarget”) to your Ship,
first of all, in this script you will have to declare a public variable (example: TargetVar ) as a Transform ( type of variable should be Transform) , in order to assign it from the Inspector.
Then in the Hierarchy (or in the scene), select the Ship, now in the inspector you will see that TargetVar is visible (as an item/slot) below the script attached, so:
drag and drop the Target Gameobject from the Hierarchy to the TargetVar slot ;
Then, you can Either use this if you want your ship to look instantly at the target:
transform.LookAt ( TargetVar.position.x, TargetVar.position.y, TargetVar.position.z ) ;
put it in the Update function of the Script…
OR if you prefer some interpolation, to gradually rotate towards the Target:
-add an empty Gameobject in your scene And name it HelperObj ;
-In your “LookAtTarget” Script, add a public variable HelperVar as a Transform, and assign it from the Inspector: to do so, Select the Ship in the scene to see its Script attached and drag drop the HelperObj to the HelperVar slot.
-Now enter these lines in the update function of the script:
HelperVar.position = transform.position;
HelperVar.LookAt ( TargetVar.position.x, TargetVar.position.y, TargetVar.position.z ) ;
Quaternion HelperRotation =HelperVar.rotation ;
transform.rotation = Quaternion.Slerp( transform.rotation, HelperRotation, Time.deltaTime * 2.0f ) ;
where the 2.0f value can be replaced by any value, greater the value faster the movement of rotation toward the Target;
tell me if you need further assistance… ^^