# Constrained knockback

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 3 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. The horizontal position (x) in the zone can be random, but should be constrained by the edges of the zone.

Question: When the enemy is hit, I want to calculate the knockback position while being constrained to the zone he will be knockbacked to.

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

I’m not sure I get the game, but I think you can accomplish it by having different game objects for each area and turning them on and off based on a state machine. The state would be what zone(s) are available to the player and you can set up tags and collision matrix in the editor game settings so that only the players collide with the barriers… and you can also add in knock back so that the player is pushed into the next zone when hit and then you would change the state for the collisions.