G
G
Gleb_Shalygin2021-07-31 13:55:08
C++ / C#
Gleb_Shalygin, 2021-07-31 13:55:08

How to stop a character in Unity2d?

When my character jumps forward, he keeps moving forward! How to make it so that after the jump the character remains on the point on which he landed?

private void Update()
    {
        if (isGrounded == true && Input.GetKeyUp(KeyCode.Space))
        {
            BallJump();
        }
     }
void BallJump()  // прыжок вперед
    {
        Vector2 jjump = new Vector2(rb.velocity.x + speed, rb.velocity.y + jumpForce);
        rb.AddForce(jjump, ForceMode2D.Impulse);
        
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PlaBetaVer, 2021-07-31
@PlaBetaVer

character velocity to 0 translate
rb.velocity = Vector3.zero, like this
or rb.velocity = new Vector3.zero

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question