- Home /
Move Object in direction of mouse?
Hi, I need to move my airplane in direction of current mouse position.
In 2D space.
Thanks!!!
Comment
does it need to follow mouse path or just to move where you click?
Try to add a force to your plane overtime, with a direction is mouse position! I don't see any thing tricky here.
Answer by Reeceg · Jul 21, 2014 at 01:18 AM
var depth = 10.0;
function Start ()
{
Screen.showCursor = true;
}
function Update ()
{
var mousePos = Input.mousePosition;
var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth));
transform.position = wantedPosition;
}