Constraining help please :)

GnomerGnomer Member Posts: 292
edited February 2012 in Working with GS (Mac)
I know this is probably quite a simple thing but I was wondering how you can constrain an actor between two certain points, so for example they can only go from 0-240, the left end of the screen to half way.

Thanks if you can answer guys :)

Comments

  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    You can either have rules set up for self.positionX in both directions, or you could simply just use 2 invisible actors with collisions so the actor can't go past those points.
  • GnomerGnomer Member Posts: 292
    Thanks @SlickZero , What if the actor is allowed in any direction, because I don't want it confined to the x axis.
  • GnomerGnomer Member Posts: 292
    I tried the collide with edges but it didnt work because the actor is set to follow the mouse and it just goes over the edges and only go back onto the constricted area when the mouse runs off the screen
  • 921creative921creative Member, PRO Posts: 140
    Can't you constrain self.positionX to self.positionX(0,240) ? (min,max) values?
  • GnomerGnomer Member Posts: 292
    I tried but it didnt work, how should i code it?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    constrain self.positionX to max(50,min(400, game.Mouse.Position.X ))

    the 50 is your left boundary and the 400 is your right boundary. Change those to whatever. Just be sure to have your parentheses right.
  • GnomerGnomer Member Posts: 292
    Thanks @Scitunes , works perfectly :)
Sign In or Register to comment.