[英]How can I retain player orientation after a button is released in C# on Unity3D?
I'm trying to flip a 3D character to get it to face the correct direction that is pressed. 我正在尝试翻转3D角色以使其面对所按的正确方向。 So far, my code is working:
到目前为止,我的代码正在运行:
private void OrientAvatar()
{
if (ControlVector.x > DeadZone)
{
Spin = -90;
}
if (ControlVector.x < DeadZone)
{
Spin = 90;
}
if (ControlVector.y > DeadZone)
{
Spin = 180;
}
Pivot.eulerAngles = new Vector3(Pivot.rotation.x, Spin, Pivot.rotation.z);
}
However, when the keys are released it'll flip direction to the opposite. 但是,释放按键时,它将向相反的方向翻转。 How can I retain the previous orientation set so that the character model remains facing in the correct direction?
如何保留以前的方向集,以使角色模型保持朝向正确的方向?
I figured it out with a few minor code corrections: 我通过一些小的代码更正找出来了:
private void OrientAvatar()
{
Debug.Log(ControlVector.x);
if (ControlVector.x >= DeadZone)
{
Spin = -90;
}
if (ControlVector.x <= -DeadZone)
{
Spin = 90;
}
if (ControlVector.y > DeadZone && Ladder)
{
Spin = 180;
}
Pivot.eulerAngles = new Vector3(Pivot.rotation.x, Spin, Pivot.rotation.z);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.