D
D
DALVROT2021-06-28 17:32:54
Unity
DALVROT, 2021-06-28 17:32:54

Unity2D How to implement jump from platform to platform?

There are two platforms (top and bottom). I'm trying to do it like this:

The code
var jumpVector = new Vector2(0, jumpSpeed * jumpDirection * Time.deltaTime);

        if (Input.GetKey(KeyCode.Space) && onGround)
        {

            characterRigidbody.AddForce(new Vector2(0, jumpForce * jumpDirection));

            while (!onGround)
            {
                characterRigidbody.velocity = jumpVector;
            }

            jumpDirection *= -1;

            characterRigidbody.gravityScale *= -1;
        }

AddForce было написано, потому что без него объект не может достаточно оттолкнуться от платформы, а скорость прыжка должна быть одной, без замедлений и ускорений.

How to do it right? I am sure that I write only crutches ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Art222222, 2021-06-28
@Art222222

I don’t rummage for the unit, but I’ll give you a tip. If the object is on the platform, then when moving the platform, do += or -= (not =, because then the object will have the same coordinates with the platform, i.e. it will be inside it) of the coordinates of both the platform and the object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question