internal static void SimpleInitShip(ShipAI shipAI) { AQAccess.Register(shipAI); if (shipAI == null) { Debug.Log("ShipAi function parameter is null -> Aborting."); return; } ShipAPI sapi = shipAI.GetComponentInChildren <ShipAPI>(); TurretAPI tapi = sapi.TurretControl; if (shipAI.ActualShipRoot == null) { Debug.Log("Missing ship root. np."); } if (sapi == null) { Debug.Log("Missing ship API. np."); } if (sapi == null) { Debug.Log("Missing turret API. np."); } AQAccess.Ins.SetData(shipAI, "Source", shipAI); AQAccess.Ins.SetData(shipAI, "Root", shipAI.ActualShipRoot); AQAccess.Ins.SetData(shipAI, "TurretControl", tapi); }
public static Transform FireRandomBakuUsaAt(Transform transform) { ShipAI a = usakiGroup[Random.Range(0, usakiGroup.Count)]; if (!a || !a.bakuUsa) { return(transform); } a.bakuUsa.SetParent(null); a.bakuUsa.gameObject.AddComponent <Rigidbody>().useGravity = false; TrailRenderer trail = a.bakuUsa.GetComponentInChildren <TrailRenderer>(); if (trail) { trail.enabled = true; } Projectile proj = a.bakuUsa.gameObject.AddComponent <Projectile>(); proj.AssignRigidbody(); proj.transform.LookAt(transform); proj.turnRate = 20f; proj.projectileSpeed = WorldManager.instance.bakuHatsuSpeed; proj.Velocity = transform.forward * WorldManager.instance.bakuHatsuSpeed; proj.SetTriggerStatus(true); proj.homeTarget = transform; return(a.bakuUsa); }
void OnDrawGizmos() { print("编译时,请注释掉最上面的#define EDIT"); if (string.IsNullOrEmpty(shipName)) { shipName = name; } Gizmos.color = new Color(1, 0, 0, .3f); if (shipData) { Gizmos.DrawSphere(transform.position, shipData.range); } Gizmos.color = Color.magenta; Gizmos.DrawWireSphere(transform.position, boundOfMove); if (animBehaviour == null) { animBehaviour = transform.GetChild(0).GetComponent <Animation>(); } if (animBehaviour) { if (animBehaviour.gameObject.layer != LayerMask.NameToLayer("CheckPath")) { animBehaviour.gameObject.layer = LayerMask.NameToLayer("CheckPath"); } } if (!selfAI) { selfAI = GetComponent <ShipAI>(); } }
/// <summary> /// Checks the exit condition of the order and, if satisfied, finishes the given order. /// </summary> /// <param name="controller">Reference to ship's AI controller</param> /// <returns>True if order should be terminated, false otherwise</returns> protected bool CheckExitCondition(ShipAI controller) { Vector3 target; // Temporary destination overrides waypoints if (controller.tempDest == Vector3.zero && controller.wayPointList.Count > 0) { target = controller.wayPointList[controller.nextWayPoint].position; } else { target = controller.tempDest; } float distance = Vector3.Distance(target, controller.transform.position); if (distance < 10) { controller.tempDest = Vector3.zero; return(true); } float thr = distance > 100f ? 1f : (distance / 100f); controller.throttle = Mathf.MoveTowards(controller.throttle, thr, Time.deltaTime * 0.5f); return(false); }
public override void UpdateState(ShipAI controller) { SteerAction.SteerTowardsTarget(controller); float distance = Vector3.Distance(controller.wayPointList[controller.nextWayPoint].position, controller.transform.position); controller.throttle = distance > 30f ? 1f : 0f; }
public void SetAIVariables(ShipAI AIParams) { shootInterval = AIParams.shootInterval; cooldownInterval = AIParams.cooldownInterval; engagementRanges = AIParams.engagementRanges; shipStats = AIParams.shipStats; shipMovementValues = AIParams.shipMovementValues; shipRotationalValues = AIParams.shipRotationalValues; }
public override void UpdateState(ShipAI controller) { SteerAction.SteerTowardsTarget(controller); if (CheckExitCondition(controller)) { controller.FinishOrder(); } }
private void CheckSingeltonInstance() { if (instance != null) { Destroy(gameObject); } instance = this; DontDestroyOnLoad(gameObject); }
private void PatrolWaypoints(ShipAI controller) { float distance = Vector3.Distance(controller.wayPointList[controller.nextWayPoint].position, controller.transform.position); if (distance < 30) { controller.nextWayPoint = (controller.nextWayPoint + 1) % controller.wayPointList.Count; } controller.throttle = 1.0f; }
private void Awake() { aiInput = new ShipAI(this, this.GetComponent <Rigidbody>()); physics = new ShipPhysics(this, this.GetComponent <Rigidbody>()); if (leader != null) { leader.subordinates.Add(this); leader.isLeader = true; inSquad = true; leader.inSquad = true; } }
public override bool IsSatisfied(FsmState curr, FsmState next) { ShipAI Ship = GetComponent <ShipAI> (); if (Ship.target == null) { return(true); } else { return(false); } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.GetComponent <ShipAI>()) { ShipAI ai = other.gameObject.GetComponent <ShipAI>(); if (waypoint.ships.Contains(ai)) { if (ai.targetWaypoint == this) { waypoint.nextWaypoint(); } } } }
/// <summary> /// Called by each of the orders to turn the ship towards a certain target /// </summary> /// <param name="controller"></param> public static void SteerTowardsTarget(ShipAI controller) { Vector3 target; // Temporary destination overrides waypoints (zeroed tempDest means it's not in use) if (controller.tempDest == Vector3.zero && controller.wayPointList.Count > 0) { if (controller.wayPointList[controller.nextWayPoint] != null) { target = controller.wayPointList[controller.nextWayPoint].position; } else { target = controller.tempDest; } } else { target = controller.tempDest; } float distance = Vector3.Distance(target, controller.ship.transform.position); if (distance > 10) { // Control the angular velocity (how quickly you are changing direction) Vector3 angularVelocityError = controller.rBody.angularVelocity * -1; Vector3 angularVelocityCorrection = controller.pid_velocity.Update(angularVelocityError, Time.deltaTime); // Convert angular velocity correction to local space Vector3 lavc = controller.ship.transform.InverseTransformVector(angularVelocityCorrection); Vector3 desiredHeading = target - controller.ship.transform.position; Vector3 currentHeading = controller.ship.transform.forward; // Control the angle itself (which direction you are facing) Vector3 headingError = Vector3.Cross(currentHeading, desiredHeading); Vector3 headingCorrection = controller.pid_angle.Update(headingError, Time.deltaTime); // Convert heading correction to local space to apply relative angular torque Vector3 lhc = controller.ship.transform.InverseTransformVector(headingCorrection * 200f); controller.angularTorque = lavc + lhc; } else { // Do not attempt to turn towards a really close target or things will become weird controller.angularTorque = Vector3.zero; } }
public override AQResult Execute() { Transform target = AQAccess.GetData("Target") as Transform; ShipAI source = AQAccess.GetData("Source") as ShipAI; Transform root = AQAccess.GetData("Root") as Transform; source.DrawGizmoSphere(root.position, range); if (target != null) { return(Vector2.Distance(target.position, root.position) < range ? AQResult.Success : AQResult.Fail); } return(AQResult.Fail); }
void HandleEnemyForgeUI() { if (currentType != selectedType) { currentType = selectedType; ShipAI dummyAIParams = AITypes[currentType].GetComponent <ShipAI>(); inputFields[0].Fields[0].text = dummyAIParams.shootInterval.ToString(); //Weapon Fire Interval inputFields[1].Fields[0].text = dummyAIParams.cooldownInterval.ToString(); //Weapon Fire Cooldown inputFields[2].Fields[0].text = dummyAIParams.engagementRanges.gunRange.ToString(); //Weapon Range inputFields[3].Fields[0].text = "0"; //Missile Fire Interval inputFields[4].Fields[0].text = "0"; //Missile Reload inputFields[5].Fields[0].text = dummyAIParams.engagementRanges.missileRange.ToString(); //Missile Range inputFields[6].Fields[0].text = dummyAIParams.shipMovementValues.maxSpeedVector.x.ToString(); //Ship Speed F/B inputFields[6].Fields[1].text = dummyAIParams.shipMovementValues.maxSpeedVector.y.ToString(); //Ship Speed L/R inputFields[6].Fields[2].text = dummyAIParams.shipMovementValues.maxSpeedVector.z.ToString(); //Ship Speed U/D inputFields[7].Fields[0].text = dummyAIParams.shipMovementValues.maxForceVector.x.ToString(); //Ship Force F/B inputFields[7].Fields[1].text = dummyAIParams.shipMovementValues.maxForceVector.y.ToString(); //Ship Force L/R inputFields[7].Fields[2].text = dummyAIParams.shipMovementValues.maxForceVector.z.ToString(); //Ship Force U/D inputFields[8].Fields[0].text = dummyAIParams.shipMovementValues.speedMultiplier.ToString(); //Boost Multiplier inputFields[9].Fields[0].text = dummyAIParams.shipRotationalValues.maxSpeedVector.x.ToString(); //Rotational Speed Roll inputFields[9].Fields[1].text = dummyAIParams.shipRotationalValues.maxSpeedVector.y.ToString(); //Rotational Speed Pitch inputFields[9].Fields[2].text = dummyAIParams.shipRotationalValues.maxSpeedVector.z.ToString(); //Rotational Speed Yaw inputFields[10].Fields[0].text = dummyAIParams.shipRotationalValues.maxForceVector.x.ToString(); //Rotational Force Roll inputFields[10].Fields[1].text = dummyAIParams.shipRotationalValues.maxForceVector.y.ToString(); //Rotational Force Pitch inputFields[10].Fields[2].text = dummyAIParams.shipRotationalValues.maxForceVector.z.ToString(); //Rotational Force Yaw inputFields[11].Fields[0].text = dummyAIParams.shipStats.hullGrade.ToString(); //Ship Hull Grade inputFields[12].Fields[0].text = dummyAIParams.shipStats.shieldGrade.ToString(); //Ship Shield Grade inputFields[13].Fields[0].text = dummyAIParams.shipStats.shieldDelay.ToString(); //Ship Shield Delay inputFields[14].Fields[0].text = dummyAIParams.shipStats.shieldRechargeRate.ToString(); //Ship Shield Regen } }
private void Awake() { // In case this is a player ship, attack AI ShipAI shipAI = GetComponent <ShipAI>(); if (shipAI == null) { isLookingForEnemy = true; } audioSource = GetComponent <AudioSource>(); audioSource.spatialBlend = 1.0f; audioSource.minDistance = 5.0f; audioSource.maxDistance = 500.0f; // add default blacklists raycastWhitelist.Add("enemy"); raycastWhitelist.Add("Enemy"); raycastWhitelist.Add("Player"); }
/// <summary> /// Checks the exit condition of the order and, if satisfied, finishes the given order. /// </summary> /// <param name="controller">Reference to ship's AI controller</param> /// <returns>True if order should be terminated, false otherwise</returns> protected bool CheckExitCondition(ShipAI controller) { // Note: this order will never end (there is no end condition)! if (controller.tempDest == Vector3.zero) { controller.tempDest = GenerateNextWaypoint(controller.transform); } float distance = Vector3.Distance(controller.tempDest, controller.transform.position); if (distance < 30) { controller.tempDest = GenerateNextWaypoint(controller.transform); } controller.throttle = Mathf.MoveTowards(controller.throttle, 0.5f, Time.deltaTime * 0.5f); return(false); }
public void addEscort(ShipAI ai) { escorts.Add(ai); }
public override void UpdateState(ShipAI controller) { SteerAction.SteerTowardsTarget(controller); PatrolWaypoints(controller); }
void Awake() { ship = GetComponent <ShipAI> (); targetPlaceholder = ship.target; }
private void Awake() { aiInput = GetComponent <ShipAI>(); physics = GetComponent <ShipPhysics>(); }
void Start() { Ship = GetComponent <ShipAI> (); huntScript = GetComponent <Hunt>(); }
void Awake() { ship = GetComponent <ShipAI> (); Reset(); flipCoins(); }
public void removeEscort(ShipAI ai) { escorts.Remove(ai); }
public void assignAI(ShipAI ai) { ships.Add(ai); ai.setWaypointNode(currentNode); }
void Start() { Ship = GetComponent <ShipAI> (); }
/// <summary> /// The main method of the Order class, invoked in the Update function of the /// ship's artificial intelligence controller. Context is provided via the ShipAI /// object which has all the needed values. /// </summary> /// <param name="controller"></param> public abstract void UpdateState(ShipAI controller);
void Start() { ship = GetComponent <ShipAI> (); findScript = GetComponent <FindTarget>(); }