Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Is there a script for in game snapping to a gri like say if i was trying to put a box anywhere in a room it coul snap onto a grid thankyou |
||||
|
I once made a level editor for my game. Code: Basically, it snaps cubes to 10x10x10 grid. editor__detector is a node which is attached to a free floating camera. It is used to place objects relative to it. First I get its position, and then update each position component, so it is rounded to tens (this.cellSize = 10); For example, if x pos === 23.5: 23.5 / 10 = 2.35; Component x is updated from 23.5 to 23. If initial value was 2.5 it will be rounded to 30 the same way.round(2.35) = 2; 2 * 10 = 20; You can regulate the grid side with different cellSize value. If it's 0.1 for example, and x position is 23.56 23.56 / 0.1 = 235.6; round(235.6) = 236; 236 * 0.1 = 23.6; Hope, you got the idea. |
|