// Player only // -1 for missDistance is used to indicate a random missDistance & random missAngle. public override void fire(PlayerInput pI, float missDistance, float missAngle, int isThisShotgun, int shotIndex, out Combat playerHit, out float playerDamageDone) { float dmg = DamageCircle.touchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle, damageDealt, 0.25f); missDistance /= (1 + 1f * DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle)); // Doubles accuracy for damage circle. Vector3 fireFromPos; if (parentPlayerMove.thisIsMine && !parentPlayerMove.GetComponent <ClassControl> ().isBot) { // Adjust so it comes out of the viewmodel gun: fireFromPos = parentPlayerMove.mainCamera.transform.position + (parentPlayerMove.mainCamera.transform.rotation * Quaternion.Inverse(parentPlayerMove.playerView.viewmodelCamera.transform.rotation)) * (viewmodelUnlockObject.transform.position - parentPlayerMove.playerView.viewmodelCamera.transform.position); } else { fireFromPos = unlockObject.transform.position; } // Modify firePos here if guns are off with method override. // Hang on! if (OperationNetwork.isServer && isThisShotgun == 0) { GameManager.rewindStatesToTick(pI.tickNumber); } Vector3[] posToSend = HitscanGun.hitscanShoot(parentPlayerMove.mainCamera.transform.position, fireFromPos, miss(parentPlayerMove.mainCamera.transform.rotation, parentPlayerMove.mainCamera.transform.forward, missDistance, missAngle), unlockObject, parentPlayerMove.GetComponent <PlayerAnimation>(), soundEffect, getBulletType(), parentPlayerMove.GetComponent <Combat>().team, dmg, 0.5f, 5 - (int)(3 * DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle)), 200, isThisShotgun, this, out playerHit, out playerDamageDone, parentPlayerMove.plyr); // Special case, PISTOL! if (this is Pistol) { ((Pistol)this).attemptConductiveExplode(posToSend [posToSend.Length - 1]); } // Hang on! if (OperationNetwork.isServer && isThisShotgun == 0) { GameManager.revertColliderStates(); } // The hitscan bullets need to be sent to the clients if (OperationNetwork.isServer) { Vector3[] sendPos = new Vector3[posToSend.Length - 1]; Array.Copy(posToSend, 1, sendPos, 0, sendPos.Length); parentPlayerMove.GetComponent <SyncPlayer> ().currentTriggerSet.trigger(SyncPlayer.HITSCAN, sendPos); } }
void swingDamage(PlayerInput pI) { if (targetHit) { return; } // Hang on! if (OperationNetwork.isServer) { GameManager.rewindStatesToTick(pI.tickNumber); } // To predict stuff like blood effects: float damage = getDamage(); damage = DamageCircle.touchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle, damage, 0.5f); // Currently, meelee does not collide with walls & stuff. (Nor allied players) Collider[] hitObjects = Physics.OverlapBox(parentPlayerMove.mainCamera.transform.position + parentPlayerMove.mainCamera.transform.forward * 1.3f, new Vector3(0.6f, 0.5f, 1.9f), parentPlayerMove.mainCamera.transform.rotation, 1 << (22 - 14 * parentPlayerMove.GetComponent <Combat>().team) | 1 << (15 - 5 * parentPlayerMove.GetComponent <Combat>().team)); // For now, hit everything, possibly an interesting mechanic. // Find the closest one, and hit that one. It also needs to be closest to the center? float bestDistance = 1.0f; // Max Range. (Kind of redundant, but it's used to round off the edges) Collider bestHit = null; foreach (Collider hit in hitObjects) { float dist = Vector3.Distance(parentPlayerMove.mainCamera.transform.position, hit.ClosestPointOnBounds(parentPlayerMove.mainCamera.transform.position)); if (dist >= bestDistance) { continue; } if (hit.gameObject.layer == 22 - 14 * parentPlayerMove.GetComponent <Combat>().team) { if (hit is UnityEngine.CapsuleCollider && hit.gameObject.GetComponent <Combat>().team != parentPlayerMove.GetComponent <Combat>().team) { bestDistance = dist; bestHit = hit; } } else if (PlayerMade.IsEnemy(hit.transform, parentPlayerMove.GetComponent <Combat>().team)) { bestDistance = dist; bestHit = hit; } } // It's a copy and paste of the code above as far as if statements go: if (bestHit != null) { targetHit = true; if (bestHit.gameObject.layer == 22 - 14 * parentPlayerMove.GetComponent <Combat>().team) { if (bestHit is UnityEngine.CapsuleCollider && bestHit.gameObject.GetComponent <Combat>().team != parentPlayerMove.GetComponent <Combat>().team) { bestHit.gameObject.GetComponent <Combat>().TakeDamage(damage, 0.75f, parentPlayerMove.mainCamera.transform.forward, false, Combat.MEELEE, true, parentPlayerMove.transform.position, parentPlayerMove.plyr); // isHitscan because it's determined playerSide. (dmg shouldn't be done if dead) } } else if (PlayerMade.IsEnemy(bestHit.transform, parentPlayerMove.GetComponent <Combat>().team)) { PlayerMade.TakeDamageObjectG(bestHit.transform, damage, parentPlayerMove.transform.position, true, parentPlayerMove.plyr); } } // Hang on! if (OperationNetwork.isServer) { GameManager.revertColliderStates(); } }