Limiting Distance of a walking Actor

Pretty new at this, but how can I limit the distance of an actor walking across the screen so he doesn't walk off the page? I'm using arrow keys to control his movement. Any tutorials or help is appreciated, thanks.

Best Answer

  • ParsSOParsSO Posts: 16
    Accepted Answer

    Make invisible actors for walls and make a bounce when your character collides with wall.

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2015

    @ParsSO said:
    Make invisible actors for walls and make a bounce when your character collides with wall.

    If you use walls, you'll need to make sure to uncheck "moveable" for the wall actors and set the bounciness attribute for the walking actor and the walls actors to 0. You can make the wall actors invisible by doing Change Attribute self.Color.Alpha to 0 outside of any rules.

    Another way is to limit the x position of the walking actor:

    Constrain Attribute self.Position.X to max(0+50/2,min(self.Position.X,568-50/2)).

    *This assumes a scene width of 568 and an actor width of 50.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • 3dgreg3dgreg Member Posts: 6

    Thanks, I'll give this a shot. Both ways seem great although I'm thinking using the constraining attribute may be a cleaner way to do it. Appreciate the information!

Sign In or Register to comment.