我正在使用 Unity3D 5 制作火车模拟器,我想在弯曲的轨道上平稳地弯曲火车车厢并在直线轨道上恢复正常,我该怎么做?
我正在使用Hermite Spline Controller C# 版本,
这是代码。
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);
}
}