- Home /
Question by
byurocks23 · Apr 03, 2014 at 12:29 AM ·
transformpositionmouse
Mouse move object along x axis
I want my object to move with the mouse only on the x-axis because the object is getting affected by another force along the y-axis. The code I currently have moves it along both.
function Update () {
var mousePos = Input.mousePosition;
var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, 10));
transform.position = wantedPos;
}
How can I have the mouse move it along the x axis without affecting what happens to the y-axis
Comment
Your answer
Follow this Question
Related Questions
How To Drag any Cube Using Mouse Click and Moved Only 1 Unit?? 2 Answers
Input.mousePosition returns coordinates as integers. 1 Answer
Get position of the closest visible vertex to mouse in scene view? 1 Answer
transform.position.y == touch position ?? 1 Answer
Place object randomly at any predefined spawn point 1 Answer