GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Constrain actor to max/min y values

leskarleskar Posts: 12Member
edited November -1 in Working with GS (Mac)
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?

Comments

  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    Have your tried something like the following?

    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))`
  • chosenonestudioschosenonestudios Posts: 1,714Member
    constrain attribute: self.position.y to max( game.P1 Y Min ,min( game.P1 Y Max , game.Touches.Touch 1.Y ))

    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! :D
  • leskarleskar Posts: 12Member
    Thanks for the quick responses!

    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...
  • chosenonestudioschosenonestudios Posts: 1,714Member
    leskar said:
    Thanks for the quick responses!

    Thanks again for the help on this!

    Probably more questions to come...

    Yep, dont worry about it :D
  • tmoritz702tmoritz702 Posts: 11Member
    Ok, have problem understanding. Trying to also set x and y mim and max. Example move up, don't want actor to move pass particular y axis.

    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?
  • tmoritz702tmoritz702 Posts: 11Member
    tmoritz702 said:
    Ok, have problem understanding. Trying to also set x and y mim and max. Example move up, don't want actor to move pass particular y axis.

    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. Please help.

This discussion has been closed.