C# 统一2D角色跳跃过多
首先,对不起我的英语不好。我的问题很清楚 我的角色有时会跳得很高 正常情况下; 有时,如果角色跳转到碰撞角,就会发生这种情况; 为什么会这样?我怎样才能解决这个问题 这是我的密码C# 统一2D角色跳跃过多,c#,unity3d,2d,collider,C#,Unity3d,2d,Collider,首先,对不起我的英语不好。我的问题很清楚 我的角色有时会跳得很高 正常情况下; 有时,如果角色跳转到碰撞角,就会发生这种情况; 为什么会这样?我怎样才能解决这个问题 这是我的密码 private void FixedUpdate() { jumpButton = GameObject.Find("Jump").GetComponent<Button>(); jumpButton.onClick.AddListener(Jump); groundC
private void FixedUpdate()
{
jumpButton = GameObject.Find("Jump").GetComponent<Button>();
jumpButton.onClick.AddListener(Jump);
groundCheck = GameObject.Find("GroundCheck").GetComponent<Transform>();
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
MoveInput = SimpleInput.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(MoveInput * speed, rb.velocity.y);
if (isGrounded && jump)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
jump = false;
}
}
public void Jump()
{
jump = true;
}
按照你的方式,你可以在每次跳跃时加速你的向上运动 为了使跳跃每次产生相同的速度,只需将y速度设置为某个值。我们可以使用jumpForce/rb.mass获得与使用ForceMode2D.Pulse的AddForce产生的值相同的值
private void FixedUpdate()
{
jumpButton = GameObject.Find("Jump").GetComponent<Button>();
jumpButton.onClick.AddListener(Jump);
groundCheck = GameObject.Find("GroundCheck").GetComponent<Transform>();
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
MoveInput = SimpleInput.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(MoveInput * speed, rb.velocity.y);
if (isGrounded && jump)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce/rb.mass);
jump = false;
}
}