0
\$\begingroup\$

I'm trying to write a common 2D game and using vectors for physics. I have 1 wall and 1 player object that can move diagonally (both are squares without rotation).

When the player object collides with the wall from the top, the wall currently pushes it back in a hard coded direction (up).

I want to find some way to calculate the "opposite" direction to push the player back.

For example: if player moves diagonally from top side to right side, the wall should oppose the downward movement and force them to move horizontally.

Diagram of movement

Black - wall
Green - Player
Red line - direction of player movement
Blue line - direction of player movement after collision
Pink line - direction I need to find
\$\endgroup\$
2
  • \$\begingroup\$ You need the collision normal. Barring that you want the collision point. Do you have that? \$\endgroup\$
    – Theraot
    Commented May 28, 2023 at 19:58
  • \$\begingroup\$ @Theraot, I added collision normal and it solved my problem, thank you for answer. \$\endgroup\$
    – ZAK
    Commented May 28, 2023 at 23:19

0

You must log in to answer this question.

Browse other questions tagged .