have this code that detect objects to be close to my GO, but i want it to detect which side of the object is aproaching to add the right side force to it:
void Update()
{
GameObject[] Bullets;
Bullets = GameObject.FindGameObjectsWithTag("Bullet");
foreach (GameObject bullet in Bullets)
{
if(Vector3.Distance(transform.position, bullet.transform.position) < 1.5f)
{
shouldEvade = true;
//print("EVADE!");
}
else
{
shouldEvade = false;
}
}
if(shouldEvade)
{
rigidbody.AddForce((transform.right * 10) * Time.deltaTime, ForceMode.VelocityChange);
}
Debug.DrawRay(transform.position, transform.forward, Color.red);
}
↧