Basically I have a red sphere that chases around green spheres. The green spheres wander around by themselves by going from randomly generated way point to randomly generated way point. Everything is working great, however no matter what I do I cannot make them continue running around after they collide with something. Instead the rigidbody spheres break their movement and fly in one direction until they hit a wall. I want to be able to send my green spheres in the opposite directions after a collision (so if their heading to (2, 1, 3) now they'd go to (-2, 1, -3) or have then choose a new way point or something. I'll post up my script any help would be appreciated. The script below just manages health and the wandering.I tried reusing the Wander function that you will see in the script for the collisions but it makes them extremely jittery and they just spaz out.
var health : int= 30;
var dead : boolean= false;
var DeadSpeed : float= 0.5;
var Speed= 10;
var wayPoint : Vector3;
function Start()
{
Wander();
}
function OnCollisionEnter(collision : Collision)
{
if(!dead && collision.gameObject.tag=="P Bullet")
{
health -= 10;
Debug.Log(health);
if ( health <= 0)
{
dead = true;
}
}
if(collision.gameObject)
{
//Make the object stop? Go in the opposite direction? or choose a new waypoint???
}
if(collision.gameObject.tag=="Player")
{
//Make the object stop? Go in the opposite direction? or choose a new waypoint???
}
}
function Update()
{
var dist : float =(Appear.ActivePos - transform.position).sqrMagnitude;
transform.position += transform.TransformDirection(Vector3.forward)*Speed*Time.deltaTime;
if((transform.position - wayPoint).magnitude < 3 && dead != true)
{
Wander();
}
if(dead)
{
if(dist >= 2)
{
transform.LookAt(Appear.ActivePos);
transform.Translate(Vector3.forward * DeadSpeed, Space.Self);
}
else
{
transform.position=Appear.ActivePos;
Destroy (gameObject);
Appear.ActiveObj.active= true;
Appear.visible.Add(Appear.ActiveObj);
}
}
}
function Wander()
{
wayPoint= Random.insideUnitSphere *120;
wayPoint.y = 1;
transform.LookAt(wayPoint);
}