void instantiateProjectile(Vector3 position, Quaternion rotation, int photonViewID, int damage, TYPE type) { GameObject projectileInstance; // = (GameObject)Instantiate (_arrowPrefab.gameObject); if (type == TYPE.ARROW_ROPE) { projectileInstance = (GameObject)Instantiate(_ropeArrowPrefab.gameObject); } else { projectileInstance = (GameObject)Instantiate(_arrowPrefab.gameObject); } projectileInstance.transform.position = position; // print (position.ToString ()); // Debug.Break (); projectileInstance.transform.rotation = rotation; PhotonView pv = PhotonView.Find(photonViewID); CombatHandler ch = pv.GetComponent <CombatHandler> (); Weapon weapon = projectileInstance.GetComponent <Weapon> (); weapon.SetOwner(ch); Arrow arrow = weapon.GetDamagingPoints()[0].GetComponent <Arrow>(); // arrow.gameObject.layer = LayerHelper.GetAttackBoxLayer(ch.GetTeam()); arrow.SetDamagableLayers(); arrow.GetComponent <Collider> ().enabled = true; if (pv.isMine) { arrow.SetIsMine(true); weapon.SetDamage(damage); } else { arrow.SetIsMine(false); } #if UNITY_EDITOR // CameraController.CC.DevCutsceneCam(); // CameraController.CC.CutsceneCamera.transform.SetParent(projectileInstance.transform); // CameraController.CC.CutsceneCamera.transform.localPosition = new Vector3(0.075f,0.04f,-0.3f); // CameraController.CC.CutsceneCamera.transform.localRotation = Quaternion.identity; #endif }
private void ShootArrow() { //Calculate the damage of the arrow //If the current animation is DRAW, then the arrow is not at full power/speed //TODO: 50% threshold (arbitrary) for when the hand is not yet drawn if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == AnimationHashHelper.STATE_DRAW) { aimTime = _animator.GetCurrentAnimatorStateInfo(0).normalizedTime; } else if (_animator.GetCurrentAnimatorStateInfo(0).fullPathHash == AnimationHashHelper.STATE_AIM) //Drawing is complete, currently 'AIM'ing { aimTime = 1f; } Transform direction = _shootingPoint; LayerMask lm = LayerHelper.GetLayerMask(_combatHandler.GetTeam()); RaycastHit hit; if (Physics.Raycast(CameraController.CC.CombatCamera.transform.position, CameraController.CC.CombatCamera.transform.forward, out hit, 100, lm)) { direction.LookAt(hit.point); } else { direction.LookAt(CameraController.CC.CombatCamera.transform.forward * 100); } // ProjectileController.PC.InstantiateProjectile (direction.position, direction.rotation, _combatHandler.GetComponent<PhotonView>().viewID, (int)(aimTime * _damage), ProjectileController.TYPE.ARROW_ROPE); // // go = PhotonNetwork.Instantiate ("Rope_05", _combatHandler.transform.position, Quaternion.identity, 0); GameObject projectileInstance = PhotonNetwork.Instantiate("RopeArrow", direction.position, direction.rotation, 0); // projectileInstance.transform.position = direction.position; // projectileInstance.transform.rotation = direction.rotation; // PhotonView pv = PhotonView.Find (photonViewID); CombatHandler ch = _combatHandler; Weapon weapon = projectileInstance.GetComponent <Weapon> (); weapon.SetOwner(ch); Arrow arrow = weapon.GetDamagingPoints()[0].GetComponent <Arrow>(); // arrow.gameObject.layer = LayerHelper.GetAttackBoxLayer(ch.GetTeam()); arrow.SetDamagableLayers(); arrow.GetComponent <Collider> ().enabled = true; arrow.SetIsMine(true); weapon.SetDamage(25); }
/// /// <summary> /// Gets the list of enemies searched from photonview list /// </summary> /// <returns>The enemies.</returns> /// <param name="ofTeam">Of team.</param> /// <param name="checkAlive">If set to <c>true</c> check alive.</param> public static List <CombatHandler> GET_ENEMIES(TEAM ofTeam, bool checkAlive = false) { List <CombatHandler> enemies = new List <CombatHandler> (); foreach (var p in AIStatusHandler.Get_ALL_PVs(checkAlive)) { CombatHandler ch = p.GetComponent <CombatHandler> (); if (ch != null) { //check if enemy if (ofTeam != ch.GetTeam()) { enemies.Add(ch); } } else { Debug.LogWarning("WARNING : this photonview must have combathandler as its component"); } } return(enemies); }
/// <summary> /// Scan for visible enemy /// </summary> public CharacterStatusHandler Scan() { CharacterStatusHandler foundTarget = null; CharacterStatusHandler tempTarget = null; //direction from eyeposition to target Vector3 dir; // //dev // //performance test between loop order and raycast // float startTime = Time.time; //cache List <CombatHandler> enemies = CombatHandler.GET_ENEMIES(_ch.GetTeam(), true); if (!_checkClosest) { enemies.Shuffle(); } //get all enemies in range foreach (var ch in enemies.Where(x => Vector3.Distance(x.transform.position, this.transform.position) < _rangeOfVision && //Check if target are in range of vision Vector3.Angle(transform.forward, x.transform.position - this.transform.position) < _angleOfVision / 2f //Check if target are in angle of vision(Field of vision) )) { //check visibility with raycast LayerMask layerMask = 1 << LayerHelper.COMMON_BODY; RaycastHit hit; if (Physics.Raycast(_eyePosition.position , ch.transform.position - transform.position //Direction from eye to target , out hit, _rangeOfVision + 1f , layerMask )) { tempTarget = ch.GetComponent <CharacterStatusHandler> (); //get closest if (_checkClosest && (foundTarget == null || Vector3.Distance(foundTarget.transform.position, this.transform.position) > Vector3.Distance(tempTarget.transform.position, this.transform.position))) { foundTarget = tempTarget; } else { if (tempTarget != null) { print("scanned : " + tempTarget.name); } //otherwise, get random Target = tempTarget; return(tempTarget); } } } //dev // if (foundTarget != null) { // print ("scanned : " + foundTarget.name); // } //if nothing found, do nearcheck if (foundTarget == null) { foreach (var ch in enemies.Where(x => Vector3.Distance(x.transform.position, this.transform.position) < _nearRoV //Check if target are in range of vision )) { tempTarget = ch.GetComponent <CharacterStatusHandler> (); //get closest if (_checkClosest && (foundTarget == null || Vector3.Distance(foundTarget.transform.position, this.transform.position) > Vector3.Distance(tempTarget.transform.position, this.transform.position))) { foundTarget = tempTarget; } else { if (tempTarget != null) { print("scanned : " + tempTarget.name); } //otherwise, get random Target = tempTarget; return(tempTarget); } } } Target = tempTarget; return(foundTarget); }