A
A
Alex Kolyhov2021-07-20 10:13:49
C++ / C#
Alex Kolyhov, 2021-07-20 10:13:49

How to bind an object to a cursor in Unity?

How to make an object in Unity be hard-attached to the cursor in 3D space? That is, so that the object is always where both the mouse cursor and the cursor determines the coordinates of the object only along the X and Z axes (the Y axis must be fixed).
Tell me please. I have been trying for a long time to find a solution on the Internet, but I found something that does not suit me. I will be very grateful.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
s7on1250, 2021-07-20
@s7on1250

The first thing that comes to mind is to set the position of the mouse to the Update method of your object. For example, transfrom.position(Input.mousePosition);
If you need to equate to the z coordinate, then as an option transfrom.position(Input.mousePosition.x, transform.position.y,Input.mousePosition.y )
Upd. Forgot to mention mouse position conversion

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question