Move the enemy object opposite to player and keep its distance relative to the player?


I’m new to unity 3d.This is my first sample 3d game. I’m trying to create a script that dog will runs after the sheep, where sheep runs away from the dog to the opposite direction of dog ,when dog comes nearer .(for example dog comes left side of the sheep,it will go to right side, if dog comes right side it wants to move left) . Finally dog wants to move the sheep into the house. After moving the sheep into house the game, stop the sheep’s movement. I’m still learning scripting though!

Look up Physics.RayCast:

Casts a ray against all colliders in the scene and returns detailed information on what was hit.

Let your dog fire those rays and use RaycastHit to find out where the hit happened.