- Home /
Laying Traps and Snapping to surface
I would like to know is there a way I can snap an object to another at runtime.
For Instance I have a room and I have 3 trap types Roof Trap Wall Trap Floor Trap
I want my character to be able to lay a trap at runtime. So the process is 1) Player Select a Floor Trap 2) Looks at spot on floor where he wants to place the trap 3)User presses button and an instance of the object is layd flatly on the floor.
Basically I want to snap the back of the Z axis of my trap to an object, like a floor wall or roof.
Yes I know its pretty much like the Game "Orcs must die" but I have another idea for it.
Answer by Statement · Dec 13, 2011 at 12:44 PM
You could make a raycast when user press button. The RaycastHit returned contain information about the location the hit occurred and the normal the face have. You could then just do:
trap.transform.position = hit.position;
trap.transform.forward = hit.normal;
Thank you I will Give it a go, long story short I am attempting to create a Spore like Builder for objects buildings and characters.
But I am fairly new to coding 3d objects and their behavior.
Thank you for the help
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Export objects to a .3DS file at runtime 1 Answer
Problems accessing other script's variable 1 Answer
AudioClip.Create() 1 Answer