Game Object Snapping Help

BlitzMax Forums/BlitzMax Programming/Game Object Snapping Help

FBEpyon(Posted 2015) [#1]
Hello Everyone,

I was hoping someone could help point me in the right direction for game object snapping.

I'm trying to get objects to snap together based on there position to each other. I wanted to be able to build a wall on the terrain and then have another wall snap to it.

I have done multiple web searches on this subject, but I keep finding things on direct world snapping (grids).

Any help would be great..

Thanks,

FBEpyon


Kryzon(Posted 2015) [#2]
Well, a snapping is like a filtering: the user wants to place an object at some position, and the snapping logic finds the best snapped position based on the user position.

So while you're dragging an object the mouse movement coordinates should be sent to this snapping class that, based on whatever tests and logic you want, produces a recommended position to put the tile in. I imagine it's the "whatever tests and logic you want" part that's giving you difficulty.
Most of the time, this recommended position will be the exact same position that the user is dragging to, but sometimes it'll be a snapped position -- it overrides what the user wants.

Your game engine will then place the tile on the position that was recommended by the snapping class.
User wants to put object at (x1, y1) 
	---> Snapping logic analyses the scene and coordinates (x1, y1), and comes up with recommended coordinates (x2, y2)
		---> Game engine positions the object at (x2, y2)