如果你看到这个gif,我有一个关于轮换的问题:https://i.gyazo.com/a1fbdbf4c125227e0bbfeda552c2981f.gif
你会注意到,当他看起来像一个“钻石”时,他的速度非常慢,是否有任何暗示让我解决这个问题?
我的代码:
void FixedUpdate(){
grounded1 = Physics2D.OverlapCircle(groundCheck1.position, 0.15f, groundLayer);
grounded2 = Physics2D.OverlapCircle(groundCheck2.position, 0.15f, groundLayer);
grounded3 = Physics2D.OverlapCircle(groundCheck3.position, 0.15f, groundLayer);
grounded4 = Physics2D.OverlapCircle(groundCheck4.position, 0.15f, groundLayer);
float movex = Input.GetAxisRaw("Horizontal");
GetComponent<Rigidbody2D>().velocity = new Vector2(movex * speed, GetComponent<Rigidbody2D>().velocity.y);
if (Input.GetKey(KeyCode.UpArrow) && (grounded1 == true)) {
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
} else if (Input.GetKey(KeyCode.UpArrow) && (grounded2 == true)) {
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
} else if (Input.GetKey(KeyCode.UpArrow) && (grounded3 == true)) {
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
} else if (Input.GetKey(KeyCode.UpArrow) && (grounded4 == true)) {
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 15), ForceMode2D.Impulse);
}
if ((Input.GetKey(KeyCode.LeftShift)) && (Input.GetKey(KeyCode.RightArrow))) {
transform.Rotate(Vector3.forward * -5);
}
if ((Input.GetKey(KeyCode.LeftShift)) && (Input.GetKey(KeyCode.LeftArrow))) {
transform.Rotate(Vector3.forward * 5);
}
}
谢谢。
答案 0 :(得分:0)
为什么不使用角速度代替transform.Rotate?
GetComponent<Rigidbody2D>().angularVelocity
你正在使用物理学进行跳跃但是使用变换函数进行旋转,最好在相同的范例中进行两种操作。