Dont let player enter certain zones

Hi. I have a complex world and have a terrain, terrains y position is 500, and have a plane under it at position 499.9 that represents water.
I move player this way:

Vector3 mov = new Vector3(-5, 0, 0) * Time.deltaTime;
                MyRigidbody.MovePosition(transform.position + mov);

I need Player cant enter to plane at position 499.9, until he have certains conditions. Like it collide with a box collider. I cant put box collider over that plane, and when player enters mark that collider at tag, its not posible.
Here you have the 2 zones players have. Zone A always can move, and zone B only can move with certains conditions.

What is the best way to do it?
Thank you and sorry for my english!

mathf.clamp or Colliders for boundary then disable with code as per your need

If the plane has collision, you can detect collisions between the plane and the player - if there is one, move him “away” - “away” is not a vector xD so you could try to add “markers” - basically empty gameobjects (or just a bunch of stored Vector3 points) on the water, then you can move the player “away” from the point - which is a vector.
So mov = (transform.position - marker).normalized * 5;

Finding the closest marker is extremly easy - just connect the markers to the parts of your water (even if the water itself is just one huge plane, the colliders of said plane can be seperated - so you don’t have to check all the markers in the game once the player collides with the water, but just the ones of one area) either in Hierarchy or via Code.

1 Like