Advanced object positioning

snappoints = object.getSnapPoints()

{ position{...} , rotation{...}, bool rotation_snap }

function moveTile(tile, move) corr = tile.getBounds().size["y"] move["y"] = move["y"] + corr tile.setPositionSmooth(move, false, false) move["y"] = move["y"] - corr end

snapPoints[index].position

object.getBounds()

{ x = ?, y = ?, z = ? }

Now that we know how to obtain the position of objects and move them, we are theoretically able to move objects at our discretion. But how do we get positions to move our objects to without laborious chore of checking every position we need with scripted objects or trial and error?The simple answer is: Snap pointsSnap points provide a convinient way to obtain global coordinates. At first we have to obtain the respective snap points associated with an object:This function will provide us a table with following content:The position and rotation tables for each snap point describe its current global position as well as its rotation. The bool rotation_snap is an indicator if the snap point is a "rotation" snap point.Using this list, we are able to move our object to a respective snap point. But there is one last thing to consider: The volume of the object. Snap points can be found on the surface of an object and are thus far nearer than e.g. a game tile would be. So the position of the snap point has to be adjusted to accomodate for the colume of the respective object. Without that, the moved object would most likely land inside the destination point, rather than on the destination point. A graphical example would be a tile in a board game that would drive inside the board instead of setting itself on the board.For this kind of adjustment, you can write a simple function:In this function, tile represents the respective object, move is the position vector of the snap point, which can be addressed via the following call on the table of snap points:In my example, the y coordinate of the position will be adjusted to place a game piece on top of a board. The position has after the transaltion to be corrected again to the original value by subtracting the height of the object.You can access the boundaries of an object, which are necessary for such adjustments, via the following call:This will provide you with an vector of the following form, describing the maximal extension of each axis: