I have a gameobject and as the mouse moves closer to it I want the gameobject to move towards the mouse.
I want the gameobjects movement to be limited so it doesn’t move too far from it’s starting position.
What I have at the moment seems to satisfy this, but as the mouse gets closer to the object the object starts moving away from the mouse (which is the opposite to what I want happening).
Start Pos is the location that the gameobject started the scene at. Set during the Start() method call.
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = Vector3.MoveTowards(startPos, mousePos, maxDistance);