Make an Object avoid another

hi!
how can i make an object1 avoid object2? so if the object2 comes towards object1, it will move away from it?

thank you very much!

var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position,forward,hit, 5)){
if(hit.collider.tag == “objecttag”){
transform.Rotate(Vector3.up * 10);
}}

What that does is point a raycast in front of your AI. If the ray hits the tag of your objecta/objectb it’ll rotate the object to avoid the other object. All you have to do to this code is change the “objecttag” to the tag of your object. Enjoy!