Constrain actor to max/min y values
leskar
Member Posts: 12
Hi!, I am just getting back into gamesalad again. It has come a long way since I was using it last Summer. Anyway, my question is this.
I have an actor whose self.position.y and self.position.x are being constrained to global variables that always track the position of this actor. This works well for what I am doing, but I would also like to set a limit for a min and max x and y value. So that the actor cannot move above the halfway point of the screen.
Sounds easy when it is written out, but I am struggling to do this in Gamesalad. Any ideas?
I have an actor whose self.position.y and self.position.x are being constrained to global variables that always track the position of this actor. This works well for what I am doing, but I would also like to set a limit for a min and max x and y value. So that the actor cannot move above the halfway point of the screen.
Sounds easy when it is written out, but I am struggling to do this in Gamesalad. Any ideas?
Comments
Rule: When ALL conditions are met:
When game.globalX <= 480
When game.globalX > 0
When game.globalY <= 160
When game.globalX > 0
---Constrain self.position.x to game.globalX
---Constrain self.position.y to game.globalY
Either that, or try doing everything in the Constrain behaviors:
---Constrain self.position.x to `max(0,min(480,game.globalX))`
---Constrain self.position.y to `max(0,min(160,game.globalY))`
The Player 1 Y Max and Min are just global integer attributes that have your limits stored in them.... (Makes it handy to just change the attributes instead of changing the entire equation all the time)
Good Luck!
And it worked like a charm, and I understand how it is working now. To explain for others who are wondering about this I constrained the actor's Y position to...
max( game.actorMinY ,min( game.actorMaxY , self.Position.Y ))
where game.actorMinY is a global of 0 and game.actorMaxY is a global of 160.
Thanks again for the help on this!
Probably more questions to come...
In my Rule I have actor receives,key,up, is down. Attribute,game global y<=240. Attribute,game global y>0. Also have a move up and down behavior in that actor.
So, when I run the game doesn't move up at all, but can move down?