[Please Help!] How Can I Make The Tip Of My Ship Follow My Cursor?

I am asking on behalf of my earlier question about this topic, but I need my ship to look at the cursor when I move it. I already have a mouse look attached to the camera and I can clearly see around at things, but I need my ship to follow it. I also want to be able to have the ship follow it when I press the “Up Arrow”. Does anyone have any links or something. Please try to provide C# code if any, thanks.

It is easiest to get things to follow if the ‘tip’ is also ‘forward’ of the object which is also positive ‘Z’ in Unity. The next issue is that you are dealing with 3D space, so by saying follow the cursor (and I’m assuming you are talking about the mouse cursor), what you really mean is follow some point projected from my cursor position into the world space beyond. To do that you need to convert the cursor position into a 3D world space position. Assuming you are using the main camera, you can do something like this in Update:

void Update() {
  Vector3 v3Pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10.0f));

Note the 10.0 represents 10 units in front of the camera.

For some games, you want to look at the object under the cursor instead of a fixed distance into the game. For these types of games, you will need to use Physics.Raycast() to find the 3D intersecton of the ray from the cursor and the objects.

Do you only want the ship to follow if the Up Arrow is pressed down? What happens if it is following and then the Up Arrow is lifted? Does it drift back to some other position or remain in whatever position was last used?