0
\$\begingroup\$

I'm trying to determine the angle NPCs are pushed in when the PLAYER collides with them, like how 'Retro City Rampage' and 'Shakedown Hawaii' do when you bump in pedestrians.

enter image description here

Here the PLAYER (green) is coming in at an angle of -45, what's the math or formula I need to be looking at to decide the new angle each NPC (red) should adopt?

\$\endgroup\$
1
  • \$\begingroup\$ Have you tried something simple, like having the NPC move away along the line from the player's position through the NPC's position? \$\endgroup\$
    – DMGregory
    Commented Aug 10, 2019 at 10:10

1 Answer 1

1
\$\begingroup\$

The two options are:

1.) NPCs run away from the player. With this one you just need to take the vector going from the player to the NPC, normalize it and set the NPCs velocity to this vector

2.) NPCs run perpendicular to the player's direction. To achieve this, you need to take the direction of the player and rotate it 90 degrees. Since there are two solutions to this (rotate it clockwise or counterclockwise) you need to decide which one to use (it can be random). For any vector \$\vec v(x,y)\$ the two vectors, that are perpendicular to it are \$\vec v'(-y, x)\$ and \$\vec v''(y, -x)\$

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .