Directional animation
Tbone
Member Posts: 49
Heres my current conundrum. I have an AI actor that reacts to my hero actor via a collision detection. The AI actor then pursues the hero. The AI has four animation states - one for each direction: up, down, left and right.
I have no problem making the AI pursue the hero. I just cant seem to be able to trigger the correct animation state. I've been trying using rules ie when the hero' X > AI X then animate UP if hero X < AI X then animate down when hero Y> AI Y then animate right etc but I get jumpy frames as it tries to pick which animation to run.
Anybody got any ideas?
I have no problem making the AI pursue the hero. I just cant seem to be able to trigger the correct animation state. I've been trying using rules ie when the hero' X > AI X then animate UP if hero X < AI X then animate down when hero Y> AI Y then animate right etc but I get jumpy frames as it tries to pick which animation to run.
Anybody got any ideas?
Comments
animationup set to 1
animationdown set to 2
animationleft set to 3
animationright set to 4
When these attributes are true your actor performs set animation(s). So you would then setup rules that upon collision change the applicable attribute to its setting to animate, with an otherwise rule that changes the attribute to 0 so that it stops the animation when that rule is not in use.
Im quite new here so dont know how feasable that would be but just trying to give an idea where possible.
I would use vectorToAngle(enemyX-PlayerX,enemyY-PlayerY).
Keep track of the Player's X and Y by constraining the x and y of the Player to global attributes PlayerX and PlayerY.
vectorToAngle will give you the position in degrees that the player is from the enemy.
So imagine you have a circle with a big "X" drawn over it - those four quadrants created by the X would be your animation directions.
i.e:
if self.positionOfPlayer is between 315 degrees and 45 degrees, show the RIGHT animation.
if self.positionOfPlayer is between 45 degrees and 135 degrees, show the UP animation.
if self.positionOfPlayer is between 135 degrees and 225 degrees, show the LEFT animation.
if self.positionOfPlayer is between 225 degrees and 315 degrees, show the DOWN animation.
does that make sense?
You could also use magnitude to track the distance between the player and the enemy like this:
magnitude(abs(enemyX-PlayerX),abs(enemyY-PlayerY))
That will give you the distance in pixels between the Player and the enemy.
You could, for example, have the enemy only attack the player when the player is within 100 pixels.
By doing it that way, you don't need to use collision detection.
Hope this helps!
Joe
Joe - I've been experimenting with the VectorToAngle as you suggested and this solution is working a treat for me. Thanks for the pointer.
Tom.
Thanks