Detect if actor position is in specific area MATH
themagicbox
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...
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
Can you state in a sentence what it is you are trying to achieve ?
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:
// 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
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