I know there's a simple answer to this I'm just not seeing. I've got a cube that I want to appear right behind the mouse cursor, constrained to the Z-plane (i.e. z=0). It'd basically be a 3D-rendered mouse pointer. What's the right way to do this?
I thought Camera.main.ScreenToWorldPoint(Input.mousePosition) would be key, but that gives me the same coordinates no matter where the mouse is.
var cursor : Transform;
var horizontalSpeed = 10;
var verticalSpeed = 10;
function Update() {
//Move the 3D cursor with the mouse
var x : float = horizontalSpeed * Input.GetAxis ("Mouse X");
var y : float = verticalSpeed * Input.GetAxis ("Mouse Y");
cursor.transform.position = Vector3(cursor.transform.position.x+x, cursor.transform.position.y+y, cursor.transform.position.z);
}
Note: This will only move the cursor on the X and Y coordinates. It does not take into account anything else. You'll want to create a second camera to render only this cube. Make sure it's not rotated at all, and is located close to the cursor. You'll also want to play around with the initial speed values to get them just right.
Good luck, hope this helps somehow. :)
That's true. If it works for you, would you mind accepting and upvoting my answer so that other users can find this solution easier? Thanks,
This is probably going to work for me, I'm looking for a [Space Runner][1] look. Hopefully I'm on the right track :) I'd upvote your answer if I could. [1]: http://www.matteley.co.uk/labs/unity3d-spacerunner/
I don't think this will keep the mouse right under the cursor (even if I get it calibrated perfectly on one computer, I imagine it might get different results on a second), but it's probably the best way to solve this problem. Thanks a bunch!
That's true. If it works for you, would you mind accepting and upvoting my answer so that other users can find this solution easier? Thanks,
– e-bonnevilleThis is probably going to work for me, I'm looking for a [Space Runner][1] look. Hopefully I'm on the right track :) I'd upvote your answer if I could. [1]: http://www.matteley.co.uk/labs/unity3d-spacerunner/
– moonpix