0
\$\begingroup\$

I'm doing a strict topdown 2D game where the character looks at wherever the mouse is pointing (same perspective as GTA 2 or Darkwood) . I want to make movement speed for strafing and backing up slower than walking forward. I'm having a hard time figuring out how to do this using Angle() and understanding vector math.

Any help would be appreciated

\$\endgroup\$
3
  • 1
    \$\begingroup\$ What are the movement controls? If I press W, do I walk upward on the screen, or forward toward the mouse? \$\endgroup\$ – DMGregory Mar 22 at 21:06
  • \$\begingroup\$ Sorry for not giving this information earlier. If you press W, you walk upward on the screen. \$\endgroup\$ – IDieForShrek Mar 23 at 7:59
  • \$\begingroup\$ have a look at this: codegrepper.com/code-examples/csharp/top+down+movement+unity \$\endgroup\$ – H3llrais3R Mar 23 at 8:15
0
\$\begingroup\$

The dot product between the movement vector and character’s looking vector will give you a scale between -1 and 1. This could help you scale your movement based on the angle that the movement differs from the looking direction.

You could also just get the absolute value of angle between these vectors and have different cases like if > 80 degrees, slow by 50% (strafing) if > 160% slow by 75% (backwards)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.