- Home /
MousePos To Transform
I making a plat-former and need to convert the mouse to a position, however its a platformer so Z must always = 0. Before you ask whether I've searched or looked at the scripting reference.... YES I have! :)
Answer by Dom3D · Dec 19, 2012 at 04:33 PM
If you want to pick a point on a "Plane" in 3D space using the mouse, you can just do that. Create a "Plane" with the right position (SetNormalAndPosition) facing e.g. towards the camera, then create a ray from the mouse position and do a raycast against the plane. Here some snippets without context:
_ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (_plane.Raycast(_ray, out distance))
{
_hitPoint = _ray.GetPoint(distance);
can you expand a bit more on the code you gave me? Im getting errors that I cannot fix with my level of knowledge of rays.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085647im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is There An OnMouseStop? 0 Answers
Smaller object jumps around bigger when dragged by mouse cursor 0 Answers
How to properly convert mouse pos to world pos 1 Answer
Moving object with mouse on release 0 Answers
I am making a 2d game and I want to make it where to can pick up bricks with your mouse 3 Answers