Directional animation

TboneTbone Member Posts: 49
edited November -1 in Working with GS (Mac)
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?

Comments

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Could you try using attributes for each animation?
    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.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Sorry the attributes could all just be 0 to start with, in the rules it could change attribute to 1 and then animation could play
  • firemaplegamesfiremaplegames Member Posts: 3,211
    hey,

    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
  • TboneTbone Member Posts: 49
    Thank you both for your help.

    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.
  • JBULLFROGJBULLFROG Member Posts: 58
    firemaplegames said:

    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.

    In the lines above, are you setting up a rule/attribute for each of these? If so how are you setting "self.positionOfPlayer" as one attribute? shouldn't you be finding both the X, and Y? I know this is an old post, but Im new to GS, and working out some of these issues for my current game.

    Thanks
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    You could do when motion is > 0.5 do the animation left, and when motion is < 0 do the right animation. Then same can be done for the y axis
Sign In or Register to comment.