private void ChaseTarget(ShipStateController controller) { ShipMotor shipMotor = controller.GetMotor(); Rigidbody ship = controller.GetRigidbody(); Rigidbody target = controller.GetTarget(); if (target == null) { return; } Steer(shipMotor, ship, target); AdjustThrottle(); Vector3 toTarget = target.position - ship.position; float angle = Vector3.Angle(ship.transform.forward, toTarget); Vector3 velocityDifference = ship.velocity - target.velocity; //Check throttle //Check angle from player //Check velocity differences //Adjust throttle //steer based on stats/throttle }
public override void Perform(StateController controller) { ShipStateController shipController = controller as ShipStateController; //Spin Spin(shipController); //Fire Fire(shipController); }
private bool LineLook(ShipStateController controller, out RaycastHit hit) { Transform shipEyes = controller.GetEyes(); Ray ray = new Ray(shipEyes.position, shipEyes.transform.forward); Debug.DrawRay(ray.origin, ray.direction * controller.GetVisionRange()); return(Physics.Raycast(ray, out hit, controller.GetVisionRange(), visionMask)); }
void Fire(ShipStateController controller) { float timeInState = controller.GetTimeInCurrentState(); if (timeInState > attackDelay) { Rigidbody shipRigidbody = controller.GetRigidbody(); Ray forward = new Ray(shipRigidbody.position, shipRigidbody.transform.forward); controller.GetWeaponSystem().Fire(forward, controller.GetTarget()); } }
public bool Look(ShipStateController controller, out RaycastHit hit) { switch (visionType) { case VisionType.LINE: return(LineLook(controller, out hit)); case VisionType.SPHERE: return(SphereLook(controller, out hit)); case VisionType.CONE: return(ConeLook(controller, out hit)); } return(LineLook(controller, out hit)); }
public override bool Decide(StateController controller) { ShipStateController shipController = controller as ShipStateController; RaycastHit hit; if (Look(shipController, out hit)) { Debug.Log("Something is seen!"); } //controller.HitToTarget(); return(false); }
public override bool Decide(StateController controller) { ShipStateController shipController = controller as ShipStateController; //False if we haven't been in the current state long enough if (shipController.GetTimeInCurrentState() < stateDelay) { return(false); } Rigidbody target = controller.GetTarget(); if (target == null) { return(false); } return(ValidatePosition(shipController, target)); }
bool ValidatePosition(ShipStateController controller, Rigidbody target) { Rigidbody myself = controller.GetRigidbody(); //False if too far away if (Vector3.Distance(myself.position, target.position) > maxRange) { return(false); } //False if we aren't facing near the target Vector3 towards = target.position - myself.position; if (Vector3.Angle(myself.transform.forward, towards) > maxAngle) { return(false); } return(true); }
private bool ConeLook(ShipStateController controller, out RaycastHit hit) { hit = new RaycastHit(); return(false); }
public override void Perform(StateController controller) { ShipStateController shipStateController = controller as ShipStateController; ChaseTarget(shipStateController); }
void Spin(ShipStateController controller) { controller.GetMotor().Roll(1f); }