Need to be good at maths :) Directional Animation
JoshKahane
Member Posts: 470
Hi
I need to do directional animation for a skeleton enemy so that when he is at certain points around the player (who is in the centre of the screen) he animates in a different direction. So for example if the skeleton is to the left of the player, he will animate left, etc.
I want eight directions, up, down, left, right, and the four diagonals. So with pen and paper I drew a circle and cut it into 8 equal sections, you can see from this where the skeleton needs to be around the player to have a certain directional animation.
E.g. Skeleton is positioned at any coordinate in the bottom middle slice so he attacks/animates upwards. I need to work out what to put into my rule in GS to tell it if in the this section animate this. This is all imagining the player is at the centre of the circle and the skeleton is attacking the player.
I was using Wolfram Alpha and here is an example of the slice at the bottom left:
http://www.wolframalpha.com/input/?i=plot+y>=2x+and+y<=0.5x
You see if the skeleton is anywhere in that area he does a certain animation. I tried putting the coordinates into GS but have been unsuccessful.
If there is an easier way or if anyone can explain in anyway how to do this I would really appreciate it, thanks!
I need to do directional animation for a skeleton enemy so that when he is at certain points around the player (who is in the centre of the screen) he animates in a different direction. So for example if the skeleton is to the left of the player, he will animate left, etc.
I want eight directions, up, down, left, right, and the four diagonals. So with pen and paper I drew a circle and cut it into 8 equal sections, you can see from this where the skeleton needs to be around the player to have a certain directional animation.
E.g. Skeleton is positioned at any coordinate in the bottom middle slice so he attacks/animates upwards. I need to work out what to put into my rule in GS to tell it if in the this section animate this. This is all imagining the player is at the centre of the circle and the skeleton is attacking the player.
I was using Wolfram Alpha and here is an example of the slice at the bottom left:
http://www.wolframalpha.com/input/?i=plot+y>=2x+and+y<=0.5x
You see if the skeleton is anywhere in that area he does a certain animation. I tried putting the coordinates into GS but have been unsuccessful.
If there is an easier way or if anyone can explain in anyway how to do this I would really appreciate it, thanks!
Comments
So you need to use VectorToAngle.
You would use it like this:
EnemyAngle = VectorToAngle(PlayerX-EnemyX,PlayerY-EnemyY)
That will give you the enemy's angle in degrees in relation to the player.
Then you need to apply what you mentioned above.
You'll need to have eight Rules, like this:
Rule
When enemyAngle >= 0
When enemyAngle < 45
Do the appropriate animation
Rule
When enemyAngle >= 45
When enemyAngle < 90
Do the appropriate animation
etc. etc....
All the way around the circle.
Hope this helps!
Joe
So you need to use VectorToAngle.
You would use it like this:
EnemyAngle = VectorToAngle(PlayerX-EnemyX,PlayerY-EnemyY)
That will give you the enemy's angle in degrees in relation to the player.
Then you need to apply what you mentioned above.
You'll need to have eight Rules, like this:
Rule
When enemyAngle >= 0
When enemyAngle < 45
Do the appropriate animation
Rule
When enemyAngle >= 45
When enemyAngle < 90
Do the appropriate animation
etc. etc....
All the way around the circle.
Hope this helps!
Joe
Two Game attributes:
PlayerX
PlayerY
(These are both constrained to the actual players X and Y position.)
Then enemy rules:
self.EnemyAngle (which is an integer)
Change Attribute:
self.EnemyAngle To: vectorToAngle(self.Position.X - game.PlayerX, self.Position.Y - game.PlayerY)
(Then animate rules:)
Attribute: self.EnemyAngle >= 22.5
Attribute: self.EnemyAngle < 67.5
Animate: (My sprites)
etc etc.
Not sure what I have done, hope that makes sense.
instead of Change Attribute to get the enemyAngle, use Constrain Attribute so it constantly fires.
I believe Change Attribute only fires once.
Everything is in the right place.
Let me know if it's still broken!
Best,
Joe
I have made identical rules just with the correct changes in the angle and he won't animate in the following directions:
Looking up/north
Looking left/west
Looking up left/north west
Looking up right/ north east
Thats the bottom half of the animations. How come? What can I do?
These are the angles I am using, animating between:
337 and 22 - looking west (wont work)
23 and 67 - looking south west (works)
68 and 112 - looking south (works)
113 and 157 - looking south east (works)
158 and 202 - looking east (works)
203 and 249 - looking north east (wont work)
250 and 292 - looking north (wont work)
293 and 336 - looking north west (wont work)
Hope you can help.
Kind regards, Josh.
0 degrees points right
90 points up
180 points left
270 points down
I would really appreciate it if someone could mock up a demo for me please. Showing when the enemy is below the player he animates a specific way, above the player... etc etc.
Or any other ideas would be helpful, thank you.
joe AT firemaplegames DOT com
and I'll take a look
http://img59.yfrog.com/img59/2853/63988381.png
I would really so very much appreciate it if someone could make a demo or help me out somehow. I felt like I was onto a great game. Looks great and great idea but I can't get what should be a simple task to happen, happen.