urgent please how to check left, right, top and bottom

FirstDanFirstDan Member Posts: 208
edited November -1 in Working with GS (Mac)
i have an rectangle as an actor and a jumping actor,

how do i detect whether the jumping actor has either touched the left, right, top or bottomof the rectangle..

thanks

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you dont need 4 different actors

    simply constrain to attributes to the rectangles x and y positions

    then compare the positions between the actor and the rectangle when they collide and you can tell where it has collided. For example:

    if the actors self position x is less then the self position x of the rectangle when it collides, you know it collided on the left of the rectangle. If the actors self position x is greater then the self position x of the rectangle when it collides, you know it collided on the right of the rectangle

    if the actors self position y is greater then the self position y of the rectangle when it collides, you know it collided on the top of the rectangle. and if the actors self position y is less then the self position y of the rectangle when it collides, you know it collided on the bottom of the rectangle

    cheers
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you dont need 4 different actors

    simply constrain to attributes to the rectangles x and y positions

    then compare the positions between the actor and the rectangle when they collide and you can tell where it has collided. For example:

    if the actors self position x is less then the self position x of the rectangle when it collides, you know it collided on the left of the rectangle. If the actors self position x is greater then the self position x of the rectangle when it collides, you know it collided on the right of the rectangle

    if the actors self position y is greater then the self position y of the rectangle when it collides, you know it collided on the top of the rectangle. and if the actors self position y is less then the self position y of the rectangle when it collides, you know it collided on the bottom of the rectangle

    cheers
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you dont need 4 different actors

    simply constrain to attributes to the rectangles x and y positions

    then compare the positions between the actor and the rectangle when they collide and you can tell where it has collided. For example:

    if the actors self position x is less then the self position x of the rectangle when it collides, you know it collided on the left of the rectangle. If the actors self position x is greater then the self position x of the rectangle when it collides, you know it collided on the right of the rectangle

    if the actors self position y is greater then the self position y of the rectangle when it collides, you know it collided on the top of the rectangle. and if the actors self position y is less then the self position y of the rectangle when it collides, you know it collided on the bottom of the rectangle

    cheers
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you dont need 4 different actors

    simply constrain to attributes to the rectangles x and y positions

    then compare the positions between the actor and the rectangle when they collide and you can tell where it has collided. For example:

    if the actors self position x is less then the self position x of the rectangle when it collides, you know it collided on the left of the rectangle. If the actors self position x is greater then the self position x of the rectangle when it collides, you know it collided on the right of the rectangle

    if the actors self position y is greater then the self position y of the rectangle when it collides, you know it collided on the top of the rectangle. and if the actors self position y is less then the self position y of the rectangle when it collides, you know it collided on the bottom of the rectangle

    cheers
  • FirstDanFirstDan Member Posts: 208
    @JohnPapiomitis

    so i constrained the rectangles x and y positions,

    in my actor i put in a rule for when it collides with the rectangle

    if actors self.position.x < game.pos.x note:(game.pos.x = rectangles self.position.x)then
    display text = left
    end if

    this works when you hit the left of the rectangle but when my actor jumps on the top left of the rectangle its still alerts left, rather than saying top...

    please help thanks
  • FirstDanFirstDan Member Posts: 208
    CAN ANYONE ELSE SHED SOME LIGHT ....
Sign In or Register to comment.