Need to be good at maths :) Directional Animation

JoshKahaneJoshKahane Member Posts: 470
edited November -1 in Working with GS (Mac)
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!

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    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
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    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
  • JoshKahaneJoshKahane Member Posts: 470
    Ahh, I see. I really over complicated that, haha. Thanks Joe, I will try and get it going later today.
  • JoshKahaneJoshKahane Member Posts: 470
    Ok, its not going too swimmingly as I get no animation at all. What I have is the following:

    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.
  • JoshKahaneJoshKahane Member Posts: 470
    Sorry to be a both but could you tell me where I need to put these rules and be a little more specific as I am just getting it wrong and hopefully with some more detail I can get it perfect. Sorry to be a pain, your being so much help!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    you have it mostly right.

    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
  • JoshKahaneJoshKahane Member Posts: 470
    Seems to be working, thanks Joe. Such small things make such a big difference. :) Will teach me to thoroughly look at these things in future. I really appreciate the help, haha, it was a pretty essential feature.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Glad you got it working!
  • JoshKahaneJoshKahane Member Posts: 470
    Ok turns out, that for some bizarre reason which is unknown to me it will only animate from 0 to 180 degrees, this normal?

    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.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    well, in GS,

    0 degrees points right
    90 points up
    180 points left
    270 points down
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    How would I get an actor to rotate as it heads towards a point using vectortoangle? The direction of movement is working pretty well but I would like for the actor to always be facing the direction it is traveling.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    think I got it
  • CaddoMoneyCaddoMoney Member Posts: 13
    scitunes - any tips on how you got it to work? I'm also trying to get my actor always pointing in the direction of travel.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    I created an angle attribute in the actor and used firemaples vectorToAngle code as described above. Then I used this actor in the accelerate angle, but to get it pointing I have had the best luck with a constrain attribute to constrain the rotation to the attribute I created. The 3 rotate behaviors didn't work right for me. And for some reason I had to constrain to attribute-90 (no idea why!. But try the constrain attribute behavior and in the drop down menu within that select rotation. Then in the expression edit menu put self.attributethatyoumade - 90. See if that works.
  • JoshKahaneJoshKahane Member Posts: 470
    Ok I am absolutely bewildered. I haven't a clue what it is. I can only animate angles between roughly 0 and 180, nothing between 180 and 360.

    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.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    can you email me a screenshot of your behaviors?
    joe AT firemaplegames DOT com
    and I'll take a look
  • JoshKahaneJoshKahane Member Posts: 470
    Thanks Joe. I will do. Here is something I very quickly mocked up to show what I want to achieve. Hope it clears it up a little.

    http://img59.yfrog.com/img59/2853/63988381.png
  • JoshKahaneJoshKahane Member Posts: 470
    Ok I am failing horribly at this. I have created a new game and just two actors. Trying to do just this from scratch with no luck still.

    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.
Sign In or Register to comment.