【发布时间】:2015-09-14 15:16:43
【问题描述】:
我正在制作一个 2.5D 平台游戏,但我无法正确旋转玩家。我只希望它在玩家左右移动时在 X 轴上旋转。我的动作脚本是这样的:
if (isWalking)
{
transform.Rotate(0, facingDir, 0);
isWalking = false;
}
else { }
if (Input.GetKey(KeyCode.Space))
GetComponent<Rigidbody>().velocity = new Vector2(GetComponent<Rigidbody>().velocity.x, jumpHeight);
if (Input.GetKey(KeyCode.A)){
GetComponent<Rigidbody>().velocity = new Vector2(-speedHeight, GetComponent<Rigidbody>().velocity.y);
facingDir = 180;
isWalking = true;
}
if (Input.GetKey(KeyCode.D))
{
GetComponent<Rigidbody>().velocity = new Vector2(speedHeight, GetComponent<Rigidbody>().velocity.y);
facingDir = 0 ;
isWalking = true;
}
我可以旋转它的最好方法是通过 transform.rotate(0,180,0) 和 (0,0,0),但是它会不停地旋转,我怎么知道玩家在 X 上移动的方向-axis 这样我就可以正确地转换。旋转?
【问题讨论】:
标签: unity3d