- Home /
How do I freeze a gameObject when MouseDrag runs over a certain Vector3?
Hey guys, I'm brand new at Unity so please bare with me if this seems like a simple question. I've added the DragRigidBody script to my GameObjectA and would like to freeze that GameObjectA at a specific x,y,z coordinate when the user drags the object over those coordinates. Basically I'm trying to create a snap to point on a different GameObjectB that the user can drag GameObjectA towards and click to.
Answer by Khada · Aug 17, 2012 at 10:15 PM
So these are the rough steps
//Check distance between both objects
float distance = (objA.transform.position - objB.transform.position).magnitude;
//If distance is less than X
if(distance < 1)
{
//snap first object to the other objects position
objA.transform.position = objB.transform.position;
}
Adapt the code to your own needs.
No worries, be sure to mark it as an answer to people know this question doesn't need answering etc.
Your answer
Follow this Question
Related Questions
Setting target position in Vector3.MoveTowards 2 Answers
Player not facing the mouse correctly 1 Answer
Creating a bouncing game without using physics - Vector3 math problem, 2 Answers
Vector3 sets to different coordinates than specified 1 Answer
Vector movement according to rotation glitching out at non-square angles. 0 Answers