- Home /
Question by
danish · Dec 21, 2012 at 07:00 PM ·
racing game
Align one moving object with other moving object
Hello , i am developing racing car game so need your assistance as i am stuck with problem, i have a road in game scene with 4 lanes(lines), i want to move one car from any one of 4 lanes and get it align with other car (vertically). here is my code.
function Update () {
transform.Translate(0,0,-25*Time.deltaTime);
var distance = Vector3.Distance(transform.position,activeWayPoint.transform.position);
if(distance<100)
{
linechange();
}
}
function linechange() {
var i :int ;
var j :int ;
var relativeposition= transform.InverseTransformPoint(activeWayPoint.transform.position);
Debug.Log(relativeposition);
Debug.Log(activeWayPoint);
if(relativeposition.x>0)
{
// Debug.Log("left");
// for ( i=1 ;i<5; i++)
while(transform.position.x !=activeWayPoint.transform.position.x)
{
relativeposition= transform.InverseTransformPoint(activeWayPoint.transform.position);
transform.Translate(1.4*Time.deltaTime,0,-.48*Time.deltaTime);
yield WaitForSeconds(1);
}
}
else
{
if(relativeposition.x<0)
{
// Debug.Log("right");
// for ( j=1 ;j<5; j++)
// {
transform.Translate(-1.4*Time.deltaTime,0,-.48*Time.deltaTime);
yield WaitForSeconds(1);
// }
}
}
activeWayPoint=target[c];
Debug.Log(c);
}
Comment
Your answer
Follow this Question
Related Questions
having problems converting this script to android 1 Answer
Can you stamp 3d models onto terrain? 1 Answer
Make an object a trigger? 1 Answer
C# Saving data to the player's computer 1 Answer
racing game timer doesnt reset 1 Answer