- Home /
Snapping a picked up object into a slot/space
In a game I'm making, there's a mechanic where I have to place a certain block of shape and place it into a corresponding whole/slot (e.g. a cube goes into a cube-shaped whole).
][2]
I want to make it so that when I approach the whole near enough with the right object for it, that it just snaps into place as if being pulled by a magnet.
][3]
And then some validation happens when all the objects have been placed in their appropriate slots. How do I do that?
[2]: /storage/temp/39760-74357.jpg
if(object.name/tag == Whatever)
{
if(objectsposition > thisdistancefromhole)
{
rigidbody.AddForce(blah)
}
}
Just a bit of codey-talk (pseudocode) to give you an idea.
Your answer
![](https://koobas.hobune.stream/wayback/20220613181859im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Pickup Bullets 1 Answer
Dragged object keeping it's original rotation. 0 Answers
Dragging an object smoothly 2 Answers
Move hit.point 1 Answer
How do I snap/assemble two or more oddly shaped objects together? 0 Answers