# Knockback to zone on non-rectangular field

I have a playing field which is divided in 4 zones (as seen on the image below)

The player (blue) is on the second zone while there are 2 enemies (red) on the third zone. When the player throws an object and hits the enemy, the enemy is knockbacked in the next zone (4) but should stay within that zone.

If the enemy was being hit on the edge of the zone, I want him to still be in the zone 4 and not outside of it (if he got knocked back). I'm not sure if the direction of the hit matters in the calculation

Question: How can I find X?

Note that it can be on any shape of playing field (triangular, hexagonal, circular, ...)

• Can you unpack that "according to the direction of the hit" in more detail? It looks like both X marks in your example moved straight leftward, even though they were hit from different directions. So what influence should the hit direction have, in other cases? Jan 26, 2020 at 22:08
• Sure to elaborate a bit more: if the enemy was more to the top of the circle (Y increase) and was being hit, I want him to still be in the zone 4 and not outside of it (if he got knocked back). I'm not sure if the direction of the hit matters in the calculation. Jan 26, 2020 at 23:21
• I've added a bit more context to the question Jan 27, 2020 at 9:01

## 1 Answer

Looks like a job for the Physics engine. I would give the boundary of your play area a Rigidbody, and when the enemy is hit you apply a force to their Rigidbody equivalent to the vector (force) of the projectile (or similar). The physics engine will try to move that enemy away, in the same direction as the projectile, but if they hit the boundary wall they would 'slide' round it.

• The boundary needs a collider, but not a Rigidbody, unless you plan to move the play field borders in real-time. Jan 30, 2020 at 14:01
• True... But only if the units have Rigidbodies. There's got to be an RB in there somewhere ;o) Jan 30, 2020 at 14:12