Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一2D角色跳跃过多_C#_Unity3d_2d_Collider - Fatal编程技术网

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;
    }
}