Change the actor graphic based on movement Left or Right

TobyToby Member Posts: 478
edited January 2012 in Working with GS (Mac)
Having issues with building what i figured would be a dead simple solution. I want an actor to automatically move left and right and have the graphic on the actor change to match the direction moved.

I found Tshirtbooth's video on direction, but this won't work for me for some reason. I assume it's because I'm interpolating the motion to a random position rather than accelerating.

My code looks like this:

Every 5 seconds
Interpolate (selfpositionX) to (random 50,975) Duration (random 3/5) Ease In Out

Rule
When self.motion.linearvelocity.X < 0
Change actor Image (e.g. left)

Rule
When self.motion.linearvelocity.X > 0
Change actor Image (e.g. right)

Any ideas?

Comments

  • LeonardDeveloperLeonardDeveloper Member Posts: 4,630
    Or when right button is pressed animate& Move(And then the walking right animation)
  • TobyToby Member Posts: 478
    I should add: This actor is not controlled by the keyboard, its an enemy so this is a little wandering routine left and right.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited January 2012
    Yeah you need to change your change image to an animate image in each rule.
  • TobyToby Member Posts: 478
    Change image or animate image makes no difference.
  • TobyToby Member Posts: 478
    Ah-ha found a simple solution:

    Create a variable (integer) called eg: currentlocation inside your actor.

    Timer
    Every 5 seconds
    Interpolate (selfpositionX) to (random 50,975) Duration (random 3/5) Ease In Out
    Change attribute (self.currentlocation) to (self.position.X)

    Rule
    When self.position.X < self.currentlocation
    Change actor Image (e.g. left)

    Rule
    When self.position.X > self.currentlocation
    Change actor Image (e.g. right)

    Works great, sometimes it helps just to talk through the logic to find a solution!
  • MotherHooseMotherHoose Member Posts: 2,456
    if you are doing a flip motion of a single image, why not changeAttribute self.Graphics.Flip Horizontally true/false

    Rule: when
    self.Position.X < self.currentlocation
    changeAttribute: self.Graphic.Flip Horizontally To: true/false (depends on the initial image's being a L or R view)

    same for > self.currentlocation

    less resource-draining than changeImage.
    but, of course, wont work if the two images are totally different! ;)

    great thinking you did on that one @Toby … pat yourself on the back!

    MH
Sign In or Register to comment.