- Home /
trying to make infinte runner,but cannot position tracks.
hey guys, am trying to make infinte runner with 3 tracks, adding 1st to end of 3rd when player passes trigger of 1st track. all three triggers at end are child of that track. but tracks are positioned at random position also tried subtracting or adding values but to no vail as below.
my code::
using UnityEngine; using System.Collections;
public class loop : MonoBehaviour {
public Transform stage1;
public Transform stage2;
public Transform stage3;
public Transform trigger1;
public Transform trigger2;
public Transform trigger3;
public int speed=10;
// Update is called once per frame
void Update()
{
transform.Translate (0, 0, .5f);
}
void OnTriggerExit(Collider other)
{
if (other.name == "trigger1")
{
stage1.Translate (0, 0, (stage3.position.z+100 ) );
Debug.Log("stage3="+stage3.position.z);
Debug.Log("stage1="+stage1.position.z);
Debug.Log("trigger1="+trigger1.position.z);
}
if (other.name == "trigger2")
{
stage2.Translate(1, 1, stage1.position.z + 100 );
Debug.Log("stage2="+stage2.position.z);
Debug.Log("trigger2="+trigger2.position.z);
}
if (other.name == "trigger3") {
stage3.Translate(1,1,stage2.position.z + 100);
Debug.Log("stage3="+stage3.position.z);
Debug.Log("trigger3="+trigger3.position.z);
}
}
}
i have attached capsule collider to player,and box collider to walls on sides of track and made it kinematic, but then also player moves through wall and fall down.
Answer by markedagain · Jul 23, 2014 at 12:46 AM
i think translate wont work if there is no rigidbody attached to the object. have u tried simply snapping them into position using transform.position ?
Answer by WilliamLeu · Jul 23, 2014 at 01:41 AM
You need to
place the entirety of a single track in a single game object, that way you can move an entire track by just transforming 1 root transform (I'm assuming there's going to doodads and artwork attached as separate GameObjects.
Place by hand a GameObject both at the beginning and end where one track meets another and have access to them in the script. Again, these are going to belong to the parent GameObject mentioned above in requirement 1.
Then when attaching the beginning of TrackB to the end of TrackA, find the difference between where TrackB is in the world, and where you want it to be, and move it by that much...
TrackB.transform.position += TrackA.TrackEnd.transform.position - TrackB.TrackBegin.transform.position.
Answer by RedDevil · Jul 23, 2014 at 06:01 AM
I did this without using parallax by spawning objects at certain positions and then destroying them after they passed the main camera(this is good if you are making a mobile game).I just atached to the pictures a rigidbody and gave them velocity to move in that direction.If you do this you just have to time them perfectly to spawn one after another.
thats true, but am gonna spawn coins on switch case, to spawn on right,middle and left. also by parallax i can make terrain seem to move,that cannot be done with tracks moving, coz it will hit performance.
i did this with several layers over 2D game and it is running very smootly on iPad
Your answer