View Single Post
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-01-2021 , 11:20   Re: Get direction player is moving relative to other player
Reply With Quote #2

This should be easily doable with a simple dot product between vectors a and b, where vector a is a unit vector in the direction from attacker's origin to victim's origin and b is a unit vector in the direction of attacker's velocity. You can think of a dot product as a projection of one vector onto the another one, like in this pic from Wikipedia's page on dot product:
.

If the a and b are parallel (that is, the attacker is moving towards the victim) then the dot product would be 1, and -1 if moving away (a and b are negatives of each other). Everything in between is, well, in between. To get a gradient between 0.5 and 1.5 it should be as simple as 1 + 0.5 * dot_product.
__________________

Last edited by klippy; 03-01-2021 at 11:22.
klippy is offline