Wednesday, January 25, 2012

Possible AI beginnings for ranged enemy

// Update is called once per frame
// Possible shooter enemy ai.. needs force backwards at certain distance
// orbits around player
void Update () {

//look at player
GameObject playerGO = GameObject.FindWithTag ("Player");
transform.LookAt(playerGO.transform.position);

this.rigidbody.AddForce(transform.forward * speed);

if (Vector3.Dot(this.rigidbody.velocity,transform.forward) < 0)
{
this.rigidbody.AddForce(transform.forward * speed * 10.0f);

}

if(this.rigidbody.velocity.magnitude >= maxVel)
{
this.rigidbody.velocity.Normalize();
this.rigidbody.velocity = this.rigidbody.velocity*maxVel;

}

}

No comments:

Post a Comment