- Home /
Drag and Drop 3D Objects around in 3D space and snap to other 3d locations with logic card shuffling
Hi,
I want to be able to drag and drop three 3D cube cards onto three 3D game spheres center locations and have it snap to place whilst never allowing two cards to occupy the same game spheres.
If the cube is dropped onto a game sphere with an occupying 3d card, it will shunt the other cubes along
The camera is pointing down over the game and the dragging is restricted to X & Z. The camera never moves.
An array that holds the live game memory locations should work but the collision and drag syntax.
Drag & Drop 3D objects in a limited 2D framework HotSpot Snap 3D Objects catch the 3d cards and snap them to the center. MemoryLocation Array to record the cards positions Logic to define the shunting of the cards
The unity3d forums post is here http://forum.unity3d.com/viewtopic.php?t=46566
What syntax should I use to detect the collisions of game card and game sphere which will allow for the shuffling of the cards.?
Answer by andeeee · Mar 24, 2010 at 04:06 PM
You can use Physics.OverlapSphere to check if the card collider overlaps with any of the spheres. Essentially, you would check all the spheres in order with a loop:-
var spherePositions: Vector3[]; var sphereRadii: float[];
function Update() { for (i = 0; i < spherePositions.Length; i++) { var cardsWithin: Collider[] = Physics.OverlapSphere(spherePositions[i], sphereRadii[i]));
if (cardsWithin.Length != 0) {
// There is something inside the sphere...
}
}
}
When you know which sphere contains the card you are dragging, it is a fairly straightforward task to shuffle the cards along. You just need to keep the card positions in an array (one for each sphere) and if a card is dropped onto an occupied sphere, just move all the following array elements along by one position.
Your answer
Follow this Question
Related Questions
How to make a drag and drop menu in 2d for a 3d game (sims 4 furniture like) 0 Answers
Snap to place 1 Answer
Drag and Drop for X and Z 0 Answers
Drag and drop 3d game 1 Answer