overlap detection??
lollipoppy811228
Member Posts: 5
I'm making a a kind of a puzzle game
and I want a certain puzzle piece, when touch is released, to go back to the original position if it is not on or close enough to the right position.
and if it is on or close enough to the right position, then it is locked in its spot and become not movable.
I having trouble with the condition or rule which checks if certain actors are close enough.
Please help!
Comments
Use magnitude to calculate the distance. Find the demo here https://forums.gamesalad.com/discussion/comment/597147#Comment_597147
Or look up this forum for other demos “magnitude”
My Gamesalad Games On App Store:
Greedy Chubby: https://itunes.apple.com/us/app/greedy-chubby/id834371213?ls=1
I'd recommend using a grid for your puzzle pieces so that you know the x/y position of any placed pieces and any empty grid squares. Snap the pieces to the center of each grid square when they are released close enough to the center of the grid square. Use the magnitude function to determine the distance to the nearest grid square by first calculating which grid square the dragged piece is closest to.
For a snap-to-grid effect, use this:
Change attribute self.Position.X to round(self.Position.X / game.gridSize) * game.gridSize
Change attribute self.Position.Y to round( self.Position.Y / game.gridSize) * game.gridSize
Attached is a demo of snap-to-grid.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User