【发布时间】:2019-04-14 03:21:17
【问题描述】:
我在夹紧枪管的度数加上其父(坦克的船体)度数时也遇到了问题,因此我可以得到与下图相同的结果。
所以脚本很简单,它使用 Y_Mouse 输入旋转桶(turretBarrel)并使用 X_Mouse 输入旋转坦克的上部(turret),以及枪管稳定。 脚本
//Note this.transform is the tanks hull
public Transform turret;
public Transform turretBarrel;
float xRot;
float angleY;
float rotY;
float minTurretRotY;
float maxTurretRotY;
Vector3 mRot;
Vector3 rot;
public void Update(){
xRot = Input.GetAxis("Mouse X") * 0.5f;
turret.transform.localRotation *= Quaternion.Euler(turret.transform.localRotation.x, xRot, turret.transform.localRotation.z);
angleY -= Input.GetAxisRaw("Mouse Y") * 0.5f;
angleY = Mathf.Clamp(angleY, minTurretRotY, maxTurretRotY);
mRot = turret.transform.rotation.eulerAngles;
rot = turretBarrel.transform.rotation.eulerAngles;
rotY = angleY;
rotY = Mathf.Clamp(rotY, minTurretRotY, maxTurretRotY);
// I'm using Quaternion.Euler for barrel Stabilization
turretBarrel.transform.rotation = Quaternion.Euler(new Vector3(rotY, mRot.y, mRot.z));
//Debug.Log(rotY +" | " + angleY + "/ Min : " + minTurretRotY+ " ; Max : " + (maxTurretRotY));
}
【问题讨论】:
-
改用
mrot = turret.transform.localRotation.eulerAngles;。 -
那行不通。
-
我真的不明白你在代码中做了什么。模型是否具有正确的层次结构?如果是这样,只需存储两个角度(并在输入时更新它们)并将炮塔和枪管的两个旋转设置为围绕相应轴(可能是 y 和 x)的纯旋转就足够了。