How could I make my object follow the mouse?

I finally hammered out a nearly complete version of my script. T’was fun. However I realized its probably needlessly complex and not user friendly; so I’m back to the drawing board looking for a better solution. The last version had a crap-ton of math!

Anyway what I need is to rotate an object to the direction of the mouse pointer when its away from center.

Perhaps its me, or maybe its just the documentation but I haven’t had any success with Lerp, Slerp, or RotateTowards. I just don’t understand what they do; how they do it; and the documentation isn’t much help. I’m not looking for source code here; just some help with this.

Perhaps somebody could point out how to use these three methods to accomplish my goal?

We don’t know if it’s a 3d game, 2d game, overhead. The mouse pointer is a 2d vector on an overlay. You can send a ray through it into the world and get a collision and point at that.

Oh! Sorry! I forgot to add that detail :stuck_out_tongue: its a 3d game (not top down). I’ve tried what you suggested though. I’ve tried creating a ray from my camera at a specified distance, then using Vector3.RotateTowards (player.rigidbody.transform.position, myRayPosition, 1, 1 ); (in summary). Unfortunately what I’ve tried does not behave as I expected…

This is what I have currently:

                        Ray mouseRay = myCamera.ScreenPointToRay (Input.mousePosition);
                        Vector3 toV3 = mouseRay.GetPoint (MAX_RAY_LEN);
                      

                        translation = new Vector3 (input.x * strafeSidewaysSpeed,  input.y * shipSpeed , 0);
                        rotation = Vector3.RotateTowards ( player.rigidbody.transform.position, toV3 ,1,1);

There’s an example in the script reference that should be close enough, however, you might need to put the target position y at the same value as the player transform.position, since the end of that ray could be anywhere.