I’m creating a game similar to this game seen here:
I currently have the train following the tracks based upon some nodes that I have setup. My question is how do I get the train to move at the same speed? The straight tracks contain two nodes for each direction while the curved tracks contain four nodes that rotate the train as it goes around the corner. Anyone have any advice that would give me some way to make the speed constant. Here’s the code that currently makes the train move through the nodes.
for(int i = 0; i < targetNodes.Length; i++)
{
while(Vector3.Distance(this.transform.position, targetNodes*.position) > .1f)*
-
{*
_ Transform childT = targetNodes*;_
_ transform.position = Vector3.Lerp(transform.position, childT.position,.05f);_
_ transform.rotation = Quaternion.Lerp (transform.rotation, childT.rotation, .1f);*_
* yield return new WaitForSeconds(.05f);*
* }*
* }*