I am making a Train Simulator using Unity3D 5 and I want to bend the train wagon smoothly at a curved track and back to normal at a straight track, how do I do it?
I am using Hermite Spline Controller C# Version,
Here is code.
using UnityEngine;
using System.Collections;
public class BendTrain : MonoBehaviour {
public Transform trainwagon2;
public Transform trainwagon3;
public Transform waypoint2;
public Transform waypoint3;
public static bool t2 = false;
public static bool t3 = false;
void OnTriggerEnter (Collider col1)
{
if (col1.tag == "b2") {
t2=true;
}
if (col1.tag == "b3") {
t3=true;
}
}
void Update ()
{
if (t2)
trainwagon2.transform.rotation = Quaternion.RotateTowards(trainwagon2.transform.rotation, waypoint2.rotation, 2);
if (t3)
trainwagon3.transform.rotation = Quaternion.RotateTowards(trainwagon2.transform.rotation, waypoint2.rotation, 2);
}
}