/// <summary> /// Manage the rotaiton of the object. /// </summary> public void Rotate() { // Dodge bullets incomming if (evade.incomming) { transform.rotation = Quaternion.Lerp(transform.rotation, evade.GetEvadeRotation(), Time.deltaTime * rotationSpeed); // Constrain rotation ALONG the Z-axis, because the ships are bound to run into each other. Quaternion newRotation = transform.rotation; newRotation.x = 0; newRotation.y = 0; transform.rotation = newRotation; return; } if (target.GetTarget() != null) { transform.rotation = Quaternion.Lerp(transform.rotation, target.GetAngle(target.GetTarget()), Time.deltaTime * rotationSpeed); Quaternion newRotation = transform.rotation; newRotation.x = 0; newRotation.y = 0; transform.rotation = newRotation; return; } }
/// <summary> /// Determines whether this instance can shoot, I.E. whether it's target is in it's feild of vision. /// </summary> /// <returns><c>true</c> if this instance can shoot; otherwise, <c>false</c>.</returns> private bool CanShoot() { GameObject targetGameObject = target.GetTarget(); if (targetGameObject == null) { return(false); } Vector3 targetDir = targetGameObject.transform.position - transform.position; Vector3 selfDir = transform.up; float angle = Vector3.Angle(targetDir, selfDir); // Debug.Log ("Angle between " + name + " and " + targetGameObject.name + " is " + angle); Debug.DrawRay(targetDir, selfDir); if (angle < attackFOV) { return(true); } return(false); }