Detect if actor position is in specific area MATH

themagicboxthemagicbox Member, PRO Posts: 82
Hello,

so in this picture there is a box in the middle with 4 shaded areas around it...is there a way to set a condition for if an actor is in the shaded area? like some type of math. I was thinking something like the if x is greater or less sign, but that is for a horizontal or vertical limit..i am trying to figure out how to detect which side of the box is collided (with and actor) and then bounce the actor in the appropriate direction. I was thinking having a rule to check the position of the actor when collided and if it is in the range stated in a math equation, it would bounce according to that.

http://postimg.org/image/gpi7v7tnf/

I tried using invisible actors on each side of the box (the top and bottom reverse the actors y velocity and the right and left reverse its x velocity) but it gets too unpredictable is the actor hits close to a corner. I guess it is detecting both and the same time and it reverse both. I was thinking maybe doing the above with invisible actors (3 squares to make each above shaded area) but i figured the same thing would happen with with two invisible actors being collided at the same time. With a check for position rule, at that moment it would check if the x,y position of the actor is in the shaded area it is in. It can only be in one position at a time instead of using invisible actors where more than one can be collided at once...

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2013
    Wow, what a long question ! :)

    Can you state in a sentence what it is you are trying to achieve ?
  • BluemoonstudiosBluemoonstudios Member Posts: 156
    Hey this might help you.



  • SocksSocks London, UK.Member Posts: 12,822
    . . . . are you just trying to work out which side an actor collides with ?

    If so can you not simply stick up four 'detection' areas and check if the actor collides with the central square while in one of these areas ?

    Here, I've drawn you a quick layout, a central square and four 'detection' areas:


    image
  • ORBZORBZ Member Posts: 1,304
    Yes, you COULD do this with math, but what @socks said is simplest and most elegant if you only have one detector. Where it breaks down though is if you have multiple detector areas. In that case it'd be easier to do the math:

    // global game attributes
    game.hitX
    game.hitY

    // in the detector actor:
    when overlaps player
    change game.hitX = self.position.X
    change game.hitY = self.position.Y

    // in the player actor
    when overlaps detector:

    // lower left quad
    rule self.position.x < game.hitX and rule.self.position.y < game.hitY
    -- do stuff

    // upper right quad
    rule self.position.x > game.hitX and rule.self.position.Y > game.hitY
    -- do stuff

    // upper left quad
    rule self.position.x < game.hitX and rule.self.position.Y > game.hitY
    -- do stuff

    // lower right quad
    rule self.position.x > game.hitX and rule.self.position.Y < game.hitY
    -- do stuff
  • themagicboxthemagicbox Member, PRO Posts: 82
    edited May 2013
    Hey everyone thank you so much for your input!!...all four sides are their own detector so if the player actor is touching both at once (which will happen a lot) both rules will execute...the rule that is executing is the bounce behaviour, so when both rules execute the player actor just bounces backwards (both linear x and y velocities are reversed instead of just one)...this is ok for the four corners of the square but not anywhere else as the double execution happens close to the end of each corner making some bounces unpredicatable


    I'll try out what orbz and socks suggested thank you but if anything I will just change all my squares to circles since tht might work better...I saw a whole post on perfect circle bounces haha
  • themagicboxthemagicbox Member, PRO Posts: 82
    Wait what are the left quad rigt quad etc areas? The sides?
Sign In or Register to comment.