Actors left and right, rapid movement check possible?

rlehmrlehm Member Posts: 320
edited November -1 in Working with GS (Mac)
I have an actor follow my actor (platformer game). The problem is, when I am above the actor and standing still, the enemy below rapidly goes back and forth in a spaz type movement. Looks awful. Here are the rules, please help :)

RULE:

self.position.x < game.playerx

change attribute: self.direction to 1

otherwise

change attribute: self.direction to -1

------------

RULE:

if self.direction = 1

change attribute: self.motion.linear.x to self.speed

animate (walking right)

---otherwise---

change attribute self.motion.linear.x to -self.speed (self attribute to change speed)

animate (walk left)

Comments

  • ShaneS429ShaneS429 Member Posts: 77
    From what it looks like.

    Whenever your follow actor is to the left of the player, it will point right and animate and move at a certain speed.

    However, since you have self.position.x <

    Then the otherwise will trigger when it is > as well as = to the player position.

    Maybe nest the entire ruleset you just posted above in the following rule

    IF Self.Position.X = game.playerx
    Change Self.Move = false (or speed or whatever you use to control the movement).

    This way, whenever the follow actor is in the same spot as the player it wont move, but if it is < or > it will move according to your rules.

    Not 100% of this but worth a shot.
  • rlehmrlehm Member Posts: 320
    ShaneS429,

    What happens with this, is movement will stop (speed) but the switching back and forth goes on. And then, it will run off in an x direction and no longer follow the player's x. I must cross his path again to get it working again.

    I tried, if self.position.x = player.x
    change att self.direction to 3

    if self.direction = 3

    animate:

    and in animate, I added only one image, with fps 0

    this did not work.
  • rlehmrlehm Member Posts: 320
    I have been trying to fix this all day. I've changed the rules around so much :( if anyone has any ideas that may return me to sanity, please help..

    I've looked through the cookbook videos, searched, etc... i remember someone a while back posting a rule that would check if there was repetition and it would stop it, I cannot locate the post. Not sure it would apply to this either.

    If this isn't possible in GS please let me know. If I should be doing this completely different, please let me know. If you don't want to help me because I have annoyed you some how, please let me know :)
  • rlehmrlehm Member Posts: 320
    Bump
  • rlehmrlehm Member Posts: 320
    Solution:

    Attribute: self.position.x < scene.Game.mainchar.Position.X+3
    Attribute: self.position.x > scene.Game.mainchar.Position.X-3

    change attribute self.motion.linear velocity.X to 0
    otherwise
    change attribute self.motion.linear velocity.X to self.speed

    (self.speed could just be a number, i have a self attribute to control)
    (mainchar is just the name of the actor on the scene)

    Anyway... I finally got it. Anyone making a platformer and you want an actor to follow/chase you... but when you are on a platform right above them you'd rather they not spaz out and change direction rapidly, just follow the above.

    good luck
Sign In or Register to comment.