W
W
WasTabon2021-04-09 21:15:12
Unity
WasTabon, 2021-04-09 21:15:12

How to disable sliding on a 2d object?

The object moves through it.
rigidbody2D.velocity
I tried to set the physical material and set it to 1, but it doesn’t work anyway

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2021-04-10
@WasTabon

private void Update()
    {
        rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y);
        if (leftPos != leftBttn.transform.position.y)
        {
            //rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y);
            speed = -5f;
        }
        else if (rightPos != rightBttn.transform.position.y)
        {
            speed = 5f;
        }
        else
        {
            speed = 0f;
        }
        rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y);
    }

I made it so that when you press the button, it shifts a little down and thereby changes the position

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question