Question by 
               Arrakktur · Jan 10, 2018 at 07:25 PM · 
                drag-and-dropfreezeposition  
              
 
              Drag and drop - how to freeze the hit object?
I've got 2 objects - a sphere and a cube. When I drag the sphere and hit the cube with it, the cube is flying away. How can I make the hit objects stay in the same position even if they are hit with the another (dragged) object? When I checked the Constraints-Freeze Position in Rigidbody, the sphere just went through the cube.
Here is the code I use to drag and drop (both objects have that script attached + rigidbody):
     private bool dragging = false;
     private float distance;
 
     void OnMouseDown()
     {
         distance = Vector3.Distance(transform.position, Camera.main.transform.position);
         dragging = true;
     }
 
     void OnMouseUp()
     {
         dragging = false;
     }
 
     void Update()
     {
         if (dragging)
         {
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             Vector3 rayPoint = ray.GetPoint(distance);
             transform.position = rayPoint;
         }
     }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Teleporting 2D object once 1 Answer
Arrays - picking a random object 0 Answers
How to end game when last item has been 'dragged and dropped'? 0 Answers
Drag UI by touch 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                