- Home /
Positioning Objects Next to Each Other in Code
This feels like a very basic question, but I have been literally tearing my hair out so any help would be greatly appreciated.
Basically, I'm creating an endless runner game and I'm using long rectangular cubes as temporary measure for the path. I'm generating the cubes dynamically, then placing them after each other. They basically are acting as tiles.
I'm positioning all these cubes using global coordinates. Basically, the script checks for the last placement, then calculates the next placement and positions it using global coordinates. The placement really occurs on a 2D grid but I find that I'm writing a lot of code to handle placing these cubes when moving around the grid.
Here's a bit of code I've written to handle one case:
walkway.gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.renderer.bounds.max.z + gameObject.renderer.bounds.size.z / 2);
I've read about positioning objects using local coordinates, but I have no idea how to determine the actual size of the cube itself. Does anyone have any suggestions and / or best practices on how to handle this issue?
Thanks for your help!
Your answer
Follow this Question
Related Questions
How do I prevent players from turning unless they are in the center of a tile? 1 Answer
How to create a rotating tiles with walls on edges of tiles? 0 Answers
grid based movement range indication? 1 Answer
Change materials of connecting objects 0 Answers
Anyone have any good ideas for a grid system that can easily check surrounding grid tiles? 1 Answer