- Home /
Move to Mouse acting odd...
I am trying to move a plane to my mouse cursor with the following script:
public float speed = 1.5f; private Vector3 target;
void Start () {
target = transform.position;
}
void Update () {
target = (Input.mousePosition);
target.z = transform.position.z;
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
However, my plane is moving about the bottom left of the screen, the screens transforms are all set to 0 (apart from x rotation which is set to 270 to move around x and y). Any help would be much appreciated, thanks! :)
unity3d c# how to animator add AnimationClip
animator.animation.AddClip(animclip, "runmm",161,177);
Input.mousePosition is in Screen coordinates. Your object is in World coordinates. How you translate between the two will depend on some factors:
Do you have an Orthographic or Perspective camera?
Is your camera at an angle with respect to the world axes?
If it is axes aligned, what axis?
If it is at an angle, what the the nature of the surface that your player is moving on.
From the code above, I'm guessing your camera has a rotation of (0,0,0), and this is a 2D game.
Your answer
![](https://koobas.hobune.stream/wayback/20220613160024im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Using moveto after instantiate? 2 Answers
Box goes through walls 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers