How to make an actor change direction based on the mouse position?

estcestc Member Posts: 13
edited November -1 in Working with GS (Mac)
Hi all

I am writing a game that requires the actor to change it's direction based on where the mouse is. For example, at the start, my actor is facing right but as soon as my mouse move/pass to the back of the actor, it will animate and flip or change the facing of the actor to right.

Does anyone how i can that?

Many Thanks

Comments

  • PhoticsPhotics Member Posts: 4,172
    From the way I understand the project, I think it's this...

    If game.Mouse.Posistion.X > self.Posistion.X
    Then change image (Right Picture)
    Else change image (Left Picture)

    Animate, instead of change image, would make the transition smoother... but that requires more images. If you're simply using rotate, and you don't want your character to look upside down, here's an alternative.

    Make two copies of your actor, one left and one right. For the right-facing actor, do something like this...

    If game.Mouse.Posistion.X < self.Posistion.X
    Then spawn actor left, destroy

    The left facing actor would be reverse.

    I think I saw a bee game around here that could have benefited from such logic.

    Destroy doesn't have to be used, as spawning and destroying may cause performance issues. Instead, "Change Position" could be used to move the left and right actors on and off the screen. When off the screen, they could be made inactive with an attribute and proper modification of the rules.
  • estcestc Member Posts: 13
    Hi,

    Thanks for the advice. My actor is working great now. Thanks a million.
Sign In or Register to comment.