
坦克在爬斜坡时,保持坦克是贴合地面前进
寻路挂在父物体上,控制姿态脚本挂在坦克子物体上
RaycastHit hit;
int Rmask = LayerMask.GetMask ("Terrain");
Vector3 Point_dir = transform.TransformDirection(Vector3.down);
if (Physics.Raycast(transform.position, Point_dir, out hit, 50.0f,Rmask)) {
Quaternion NextRot=Quaternion.LookRotation(Vector3.Cross(hit.normal,Vector3.Cross(transform.forward,hit.normal)),hit.normal);
transform.MoveRotation(Quaternion.Lerp(transform.rotation,NextRot,0.1f));
}
本文介绍如何在Unity中实现坦克模型跟随地形并调整姿态的技巧,通过使用Raycast检测地形并计算适当的旋转,确保坦克平稳地在斜坡上行驶。
739

被折叠的 条评论
为什么被折叠?



