Hi
I’m currently trying to make a temple run style game.
I have written a script which allow me to instantiate a number of cubes in a row, I’ve called this my “Path builder” i was wondering how do i change the direction in which the row is created.
function makePath()
{
for (var x = 0; x < brickLength; x++)
{
nextPosition += (cube.renderer.bounds.size.x);
yPosition = (cube.renderer.bounds.size.y);
var cube = Instantiate(cube, Vector3 ( nextPosition,(yPosition)*0.5 ,0 ), transform.rotation);
cube.name = "cube"+x;
}
}
every thing i try seems to just change the actually instantiated object…
A simple way to control the direction is to use a unit vector dir showing the direction - you can assign Vector3.forward to go in this object’s forward direction, Vector3.right to the right Vector3.left to the left, etc. This dir vector is rotated according to the current transform rotation, thus it’s actually relative to the object to which this script is attached.
var dir: Vector3 = Vector3.right;
function makePath()
{
dir = transform.TransformDirection(dir); // rotate dir to the current transform orientation
var nextPos = Vector3.zero; // calculate positions in nextPos
nextPos.y = cube.renderer.bounds.size.y * 0.5;
for (var x = 0; x < brickLength; x++)
{
nextPos.x += dir.x * cube.renderer.bounds.size.x;
nextPos.z += dir.z * cube.renderer.bounds.size.z;
var cube = Instantiate(cube, nextPos, transform.rotation);
cube.name = "cube"+x;
}
}