public override void Activation(int chainNum) { Vector3 _position = GameManager.instance.playerList[1].transform.position; SentryGun sentryGun = Instantiate(_sentrygun, new Vector3(_position.x + 0.3f, _position.y + 2.0f, _position.z), Quaternion.identity); sentryGun.transform.parent = GameManager.instance.EffectHolder.transform; sentryGun.speed = speed; sentryGun.Damage = Damage; sentryGun.ChainNum = chainNum; }
// Use this for initialization private void Awake() { if (instance == null) { instance = this; effect = instance.EffectPrefab.GetComponent <ParticleSystem>(); } else if (instance != this) { Destroy(instance.gameObject); instance = this; effect = instance.EffectPrefab.GetComponent <ParticleSystem>(); } }
public override void Activate() { base.Activate(); Action = AgentActionFactory.Create(AgentActionFactory.E_Type.Melee) as AgentActionMelee; Action.Target = Owner.BlackBoard.Desires.MeleeTarget; SentryGun sentryGun = Action.Target as SentryGun; if (null != sentryGun) { // leg attack Action.MeleeType = E_MeleeType.First; } else { Action.MeleeType = RandomEnum <E_MeleeType>(); } Owner.BlackBoard.ActionAdd(Action); }
// Update is called once per frame public override void Update() { if (Owner.IsBusy || Owner.IsInCover || Owner.IsEnteringToCover || Owner.IsLeavingToCover || !Owner.IsAlive) { Owner.BlackBoard.Desires.MeleeTarget = null; return; } Vector3 FromDirection; Vector3 FromPosition; // new version of melee target (testing) if (null != GameCamera.Instance) { FromDirection = GameCamera.Instance.CameraForward; FromPosition = CenterTransform.position; RaycastHit[] hits = Physics.RaycastAll(FromPosition, FromDirection, 3.0f); //Debug.DrawLine(FromPosition, FromPosition + FromDirection*3.5f, Color.red, 1); //sort by distance if (hits.Length > 1) { System.Array.Sort(hits, CollisionUtils.CompareHits); } foreach (RaycastHit hit in hits) { //Debug.DrawLine( hit.point, hit.point + hit.normal*0.1f ); if (hit.transform.IsChildOf(Owner.Transform)) { continue; } GameObject hitObj = hit.transform.gameObject; SentryGun sentryGun = hitObj.GetComponent <SentryGun>(); if (null != sentryGun) { if (sentryGun.IsAlive == true) { Owner.BlackBoard.Desires.MeleeTarget = sentryGun; return; } } AgentHuman Human = hitObj.GetComponent <AgentHuman>(); if (null != Human) { if (Human.IsAlive == false || Human.IsInCover || Human.IsLeavingToCover || Human.IsEnteringToCover || Human.IsInKnockdown || Owner.IsFriend(Human)) { continue; } float y_delta = Mathf.Abs(Human.Position.y - Owner.Position.y); // TODO : add more sophisticated test (like sweep test against target) if (y_delta < MaxYDelta) { Owner.BlackBoard.Desires.MeleeTarget = Human; // Debug.Log("Find human by direct test" + Human.name); return; } } // wall hit etc .. break; } //second test AgentHuman bestP = null; float bestD = 3.5f * 3.5f; float bestA = 30.0f; FromPosition = CenterTransform.position; FromDirection.y = 0; FromDirection.Normalize(); // Debug.DrawLine(FromPosition, FromPosition + FromDirection, Color.red, 1); int rayCastMask = ~(ObjectLayerMask.IgnoreRayCast | ObjectLayerMask.Ragdoll | ObjectLayerMask.Hat); RaycastHit rayCastHit = new RaycastHit(); foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players) { AgentHuman agent = pair.Value.Owner; if (agent.IsAlive == false || agent.IsInCover || agent.IsLeavingToCover || agent.IsEnteringToCover || agent.IsInKnockdown || Owner.IsFriend(agent)) { continue; } if (agent == Owner) { continue; } Vector3 dirToTarget = agent.ChestPosition - FromPosition; if (Mathf.Abs(dirToTarget.y) > MaxYDelta) { continue; //too big hight diff } dirToTarget.y = 0; float d = dirToTarget.sqrMagnitude; if (d > bestD) { continue; // too far } dirToTarget.Normalize(); float a = Vector3.Angle(FromDirection, dirToTarget); // Debug.DrawLine(FromPosition, FromPosition + dirToTarget, Color.white, 1); if (a > bestA) { continue; // not looking at him } dirToTarget = agent.ChestPosition - FromPosition; if (Physics.Raycast(FromPosition, dirToTarget.normalized, out rayCastHit, dirToTarget.magnitude, rayCastMask) == false) { continue; } if (agent != rayCastHit.transform.GetComponent <AgentHuman>()) { continue; } bestP = agent; bestD = d; bestA = a; } // if(bestP != null) // Debug.Log("Find human by coll test" + bestP.name); Owner.BlackBoard.Desires.MeleeTarget = bestP; } }