- Home /
How can you allow the player to use Vertex Snapping in order for them to build a vehicle.
I need some documentation on this. Even if you can show me a simple code by example I can figure this out. So far I have looked into mathf but I am stuck.
Vertex snapping for the player? Do you have a mesh editor in your game or do you talk about the Unity editor? Can you be expand your description "a little bit" because it's not clear what you're doing here...
If you really want something like the vertex snapping function in the Unity editor in game, it's not that trivial since you have to find near geometry and search for the best fitting vertex, but first of all you need to be able to pick a target vertex.
I am trying to get the user to make make their own vehicles. So they can place items anywhere they want onto the "body" of the car or plane. Think of something like 'lego racers' or gummy ships in $$anonymous$$ingdom hearts, for the PS2. I need to know how to get the items to attach to another item from a drag and drop input.
Answer by Vonni · Jan 04, 2013 at 10:09 PM
Could you maybe create custom "joints" which you could use to attach these parts together on?
If not, i recentrly did something similar myself.
used raycast to assign an object to a lastHoveredObject varible. -Then it stores all vertices of that objects mesh to an array I keep reseting as I get new targets.
also converted all the vertices in the array to screenposition and then iterated through them all to check if they were touching my invisible rectangle near my mouse, and chose the closest vertex and placed a GUITexture on it. -It then stored that worldposition (Vertex) as a Vector3 varible i used to place an element there.
Don't have the code I used here I'm afraid, but should get you started!
Answer by DaveA · Jan 05, 2013 at 12:37 AM
I did this for a sorta Lego game. What I did was assign 'snap points' (empty game objects) as children of the object. Then a script converts the location of those snap points to world coords. As the mouse position (ray casted into the scene) is a minimum distance from any snap point, the dragged part snaps there. Use the snap point's transform and possibly a snap point on the dragged object to align the parts x,y,z, and have fun with the rotations lining up (a bit trickier but doable).
If you really just need the vertices on a mesh, then you can create an array of vertices and TransformPoint the mesh's verts into it to have a handy list of world-space points to look through.
Your answer
Follow this Question
Related Questions
how can i make an explosion 2 Answers
Rotating object towards mouse point 1 Answer
3D Grappling Hook? 0 Answers