Adding Walls with the Cross Platform Controller Template
Goodnight Games
NYCMember, PRO Posts: 184
I'm currently using the cross platform controller template to give my game touch screen analog controls for movement. The problem is I'm not sure how to constrain the player's movement so he doesn't go off the screen on the Y axis.
I've tried putting in walls and using the collide behavior but he just winds up spinning out of control. I also tried if he collides with a wall max speed is 0 but then he just sticks to the wall and can never get off of it.
I'm thinking that since the movement is based on an angles I would have to limit the angle of movement and stop him when he goes where I don't want but I can't seem to think of how to attempt it.
Has anyone had any experience with this? Thanks!
I've tried putting in walls and using the collide behavior but he just winds up spinning out of control. I also tried if he collides with a wall max speed is 0 but then he just sticks to the wall and can never get off of it.
I'm thinking that since the movement is based on an angles I would have to limit the angle of movement and stop him when he goes where I don't want but I can't seem to think of how to attempt it.
Has anyone had any experience with this? Thanks!
Best Answer
-
tatiang Posts: 11,949I don't have a lot of experience with that particular template but in general this is how you constrain an actor (assuming iPad landscape):
Constrain Attribute self.position.Y to max(0+self.size.Height,min(768-self.size.Height,self.position.Y))
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
Here is the best advice I can give in regards to it...
Take what you want, leave the rest.
Start a new project now.
Use the template as just that... a template or a reference to the way you want it.
Dont build your project on it.
(This is only constraining while the character is attempting to leave the play area.)
When
self.position.y >or= ScreenSize - self.size.width/2
constrain self.position.y to ScreenSize - self.size.width/2
self.position.y >or= 0 + self.size.width/2
constrain self.position.y to 0 + self.size.width/2