constraint x position with a margin

tabelortabelor Member Posts: 114
edited November -1 in Working with GS (Mac)
hey there everyone!
I would like to constraint my actor x position when he overlaps or colide with a transport platform....
The actor x position is constrained by the platform x position, so when the platform is moving, the actor move with and don't fall....
But the problem is i can't move the actor from left to right when i'm inside the platform because his x position is constrained to the x position of the platform, so i would like to do this same operation, but with a little margin, so the actor can move from left to right of the plaftorm but without falling....

Is this posible???
thanks a lot!

Comments

  • tabelortabelor Member Posts: 114
    i havn't explained well. What i want to constrain is the x position, not the motion, because in my game my actor move like in doodle jump, with a constrain in the x position and the accelerometer. So i need to constrain again my actor x position to the platform, but i would like a margin... like this, even if the plaftorm and the actor are moving together, the actor can still move from left to right over the plaftform and for example can take an item or avoid enemies.
    I know i need to use the max min function, but i don't know how, anyone can help me please?
  • tabelortabelor Member Posts: 114
    it's ok guys, i got it!
    I will tell how to do because maybe it can help somebody.

    Constrain x position two times, one with max function and another one with min function.
    Supose your platform width is 100, then the first constrain would be:

    constraint self.xPosition to max(self.xposition, game.plaftformXposition -50)

    the second constraint would be:

    constraint self.xPosition to min(self.xposition, game.plaftformXposition +50)

    the actor can now move over the moving platform but never fall.
    cheers!
  • GraybayGraybay Member Posts: 114
    Thanks for sharing this info tabelor, pretty good start for my left/right platforms.
  • AsymptoteellAsymptoteell Member Posts: 1,362
    Just a suggestion to help with performance: I'm pretty sure it will run faster if you combine them to be max(game.platform.x-50,min(self.position.x,game.platform.x+50))

    I could be wrong, but I think this will still work, and will increase performance.
Sign In or Register to comment.