Limiting Distance of a walking Actor
3dgreg
Member Posts: 6
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
-
ParsSO Posts: 16
Make invisible actors for walls and make a bounce when your character collides with wall.
Answers
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
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!