# Thread: How do you make an object react depending on which side another object is closer to?

1. ## How do you make an object react depending on which side another object is closer to?

Just for an example, in a top-down view, say you had a martial artist or a boxer as an object, and then an enemy object, or a thug or something, draws near. Say if the thug was closer to the left side of the boxer than the right side, and you want to make a boxer throw out a punch with the hand that's closer to the boxer (the left side), how would you code that?

Sleepy at the moment so I hope this post makes sense.

2. I would create two or three invisible of detection zones around the boxer. Next create events based on what happens if a thug enters a zone.

Think of being in fight. Punches or kicks you use are based on how far away the enemy is. If they are just in the largest zone you might use a kick but you will not use a upper cut.

I hope some day actives will have detection zones as a property option. This issue seems to come up a lot.

3. markers are easiest, or you could do loops on the enemies distance to player and determine that way.

4. danjo:

What are markers?

5. I think what danjo means is a defined zone, that could determined by actives set out as distance markers. The markers could be positioned to the enemy boxer and if the player is overlapping the markers certain actions would be possible.

6. I already have loops set up in some regard. Unfortunately I'm trying to avoid having extra objects in the scene since I already have a ton.

How would you go about writing out the code/ math about a thug enemy being closer to the left side of the boxer than the right?

7. If X Position of Thug is < X Position of Boxer, Thug is on the left. If X Position of Thug is => X Position of Boxer, he's on the right. You can put the equality condition on either side you want, just make sure you handle it.

8. The only problem with this is that the thug can also rotate. So if he's turned completely around/ 180 degrees, then the X position checks won't work right.

9. It would still work if you put in a condition that checks if the thug has rotated 180 and then inverse Christian’s suggestion. If you need more help, I suggest you put up a simplified mfa file.

10. From what I understood, you wanted this sort of thing? BoxerThugExample.mfa

Basically you get two angles: Player's current and angle from player to thug, then you compare them together to find out whether the left or right side is closer.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•