在我在设备中运行的 unity2D 游戏中,当与地面碰撞时,玩家速度设置不为零,并且我使用 FixedUpdate() 函数进行玩家翻动,我的玩家翻动在静态位置。
void FixedUpdate ()
{
// Jump
if (isAlive)
{
if (didFlap) {
didFlap = false;
myRigidbody.velocity = new Vector2(0,bounceSpeed);
anim.SetTrigger ("Flap");
}
}if (myRigidbody.velocity.y >= 0) {
transform.rotation = Quaternion.Euler (0, 0, 0);
} else {
float angle = 0;
angle = Mathf.Lerp (0,-45,-myRigidbody.velocity.y/7f);
transform.rotation = Quaternion.Euler (0, 0, angle);
}
}
void OnCollisionEnter2D(Collision2D target)
{
if (target.gameObject.tag=="Ground")
{
die();
}
}
void die()
{
if (isAlive)
{
isAlive = false;
anim.Play ("Died");
myRigidbody.velocity = Vector2.zero;
}
}