- Home /
Drag and Drop and snap between the edges!
Hi
i'm new in unity i follow your forum often but now i have a question for you. I looked in the forum and there isn't a reply to my question. If there is one, please can you post me the link.
So the question is: i have two cubes and i need to drag and drop one of the cubes on the other cube and when the cube is really near i need to snap it to the other like a magnet but not in the center they need to match the edge of the face!
let me know if all is clear
Thanks,
Roberto
You can set the six possible positions of the dragged cube corresponding to the planes of the static cube. So if it is a unitary cube, these positions would be unitary vectors drawn from its centre in six directions. Then set the "snap range "and then check the transform position of the dragged cube if within the range, if yes then set its position and stop dragging.
Answer by ciroby · Jun 21, 2012 at 02:51 PM
can you post me an example...or something.
And if the other cube is not static so what i mean is i can drag&drop and snap both cubes. How i can check the coordinates?
Thanks,
Roberto
Static - I mean you can drag one cube at a time with mouse. So I named the other one as static. And the question is how do you intend to drag it? I mean If you want to drag it in 3d space you need a gizmo, if you drag it on a plane you just pick, cast the mouse position to the plane, and drag.
You can modify and use the drawRigidBody.js script from the Shadow Demo example project.
Your answer
Follow this Question
Related Questions
Coding Advice Needed: Building a 2D ship editor 1 Answer
When is the OnDrop method called? IDragHandler 1 Answer
Drag n Drop in a 3D orthographic environment 1 Answer
[NGUI] - Drag and drop 2 Answers
Grab and throw object immediately 1 Answer