车辆模型需要放在父物体下
private Ray ray;
private RaycastHit hit;
// Update is called once per frame
void Update()
{
//计算车辆姿态
ray = new Ray(transform.position+ transform.up, -transform.up * 10);
Debug.DrawRay(transform.position + transform.up, -transform.up * 10, Color.yellow);
if (Physics.Raycast(ray, out hit))
{
Debug.DrawLine(hit.point, hit.point + hit.normal, Color.red);
Quaternion NextRot = Quaternion.LookRotation(Vector3.Cross(hit.normal, Vector3.Cross(MarkerModle.transform.forward, hit.normal)), hit.normal);
MarkerModle.transform.rotation=(Quaternion.Lerp(MarkerModle.transform.rotation, NextRot, 0.1f));
}
}