Calc direction vector based on destination vector and distance from enemy in AS3
Posted
by
Phil
on Game Development
See other posts from Game Development
or by Phil
Published on 2012-06-23T21:53:38Z
Indexed on
2012/06/24
3:25 UTC
Read the original article
Hit count: 273
actionscript-3
|vector
I'm working on a zombie game in AS3 where I want a character to be able to move away from a zombie depending upon how close the zombie is. The character also has a destination that it's trying to get too on the screen.
Ok so I have 2 vectors, one pointing to my destination, and one pointing to the zombie which I then invert to get my "away" vector. I then turn the distance between my character and the zombie into a value between 0 and 1. And then I'm stuck on how to get a resultant vector for my character. How would I use my 0-1 value to calculate how much of the away vector is used and how much of the original destination vector is still left if that makes sense? to end up with 1 direction vector to move my character? So if the zombie is right where my character is, then my direction vector = away vector, and if I'm far away from the zombie than my direction vector = destination vector, but how do I calculate the in-between?
Ideally need the answer in AS3.
© Game Development or respective owner