Hi I am truly stumped at this I have been looking for something that would script an object placement almost like when I have the object on mouse click and it snaps to the spot like a book on a shelf or a plate on a table…I read somewhere about a spawn point on a object like a bookshelf or something like that I’m not sure how to go about this??
If i understand you correctly, then you want to place objects on other objects, rather than “snapping” them to something. In that case you want to cast a ray through the camera at the position of your mouse, detect where it hits and then use that position to place your objects. Since the raycast hit will tell you the collision coordinate, that’s the surface of something (for example table or shelf) you can now place your items on. Below i’ll link a nice video on the topic:
Also i must say that your title is rather confusing, since Shelfs or Tables are only your specific examples and have little to nothing to do with the actual question, unless i misunderstood you ^^
I’m sorry that I wasn’t being specific I actually meant snapping a book to a shelf to 1 spot on the shelf or say If had a plate of food dragging it with mouse it snaps on top of the table in 1 spot when I move the mouse near the area on the table…I’m not sure if I’m explaining it well I’m sorry
Ok then you actually meant snapping and i just misunderstood you. The concept is very similar tho. You’d start by doing what i explained above (and the video), and then only update the position of your object when the mouse is close enough to the desired target location. So for example, if the distance to your desired target location is smaller than some threshhold (for example 1 meter), then snap it to the desired location. Else dont, or move freely, or whatever may be the default behavior.
I’d start by implementing a system similar to the video, where you can just move your item in the scene with a raycast through the mouse. Afterwards you can adjust the behavior to fit what you had planned. If you need additional information you will probably find lots of results when you look up “Unity Grid Snapping Script” or something along those lines. You dont want to snap to a grid, but the idea is pretty similar. It all boils down to only moving the object if it’s close enough tho.
Of course, the forum is always here to help you, but i believe you wanted to be pointed in the right direction for now ![]()
Yes this is it thanks a lot I could not get this down for the longest but I kind of get it now!!