Hi i need know how i can make that the arm a robot follow the cursor
Someone have a idea? ![]()
------|
Picture of the robot: http://i47.tinypic.com/161mir.png
Hi i need know how i can make that the arm a robot follow the cursor
Someone have a idea? ![]()
------|
Picture of the robot: http://i47.tinypic.com/161mir.png
The cursor is in 2D space, in screen coordinates. The arm is in 3D space, in the 3D world.
So the first thing you need to do is to make that 2D point into a 3D coordinate. Basically, you would need to “unproject” a point from the camera plane to the world. This unprojection creates a ray into 3d space. You would need to choose a distance along that ray to define a point in 3D space.
In Unity you can do that simply with:
Vector3 pointInWorld = Camera.ScreenToWorldPoint ( pointInScreen.x, pointInScreen.y, distance );
If you want the arm to point exactly at the place where the cursor “appears” to be in the Camera plane, you would use the Near plane of the camera, like this:
Vector3 pointInWorld = Camera.ScreenToWorldPoint ( pointInScreen.x, pointInScreen.y, camera.nearClipPlane);
That’s the point where you want to make the Rotation of the arm to point to. To point you can use :
transform.LookAt (pointInWorld);
You can get the cursor position with : Input.mousePosition
Is the arm a child object of the robot? What do you want to happen if the object to point at causes the arm to intersect the body of the robot? If you are asking about the robot rotating and the arm going up and down, do a Google search on UA for "turret" rotation. I and others have posted scripts for this type of movement.
– robertbu