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.
__________________