private void OnCollisionEnter(Collision collision) { if (this.inFlight) { Rigidbody component = base.GetComponent <Rigidbody>(); float sqrMagnitude = component.velocity.sqrMagnitude; bool flag = this.targetPhysMaterial != null && collision.collider.sharedMaterial == this.targetPhysMaterial && sqrMagnitude > 0.2f; bool flag2 = collision.collider.gameObject.GetComponent <Balloon>() != null; if (this.travelledFrames < 2 && !flag) { base.transform.position = this.prevPosition - this.prevVelocity * Time.deltaTime; base.transform.rotation = this.prevRotation; Vector3 a = Vector3.Reflect(this.arrowHeadRB.velocity, collision.contacts[0].normal); this.arrowHeadRB.velocity = a * 0.25f; this.shaftRB.velocity = a * 0.25f; this.travelledFrames = 0; return; } if (this.glintParticle != null) { this.glintParticle.Stop(true); } if (sqrMagnitude > 0.1f) { this.hitGroundSound.Play(); } FireSource componentInChildren = base.gameObject.GetComponentInChildren <FireSource>(); FireSource componentInParent = collision.collider.GetComponentInParent <FireSource>(); if (componentInChildren != null && componentInChildren.isBurning && componentInParent != null) { if (!this.hasSpreadFire) { collision.collider.gameObject.SendMessageUpwards("FireExposure", base.gameObject, SendMessageOptions.DontRequireReceiver); this.hasSpreadFire = true; } } else if (sqrMagnitude > 0.1f || flag2) { collision.collider.gameObject.SendMessageUpwards("ApplyDamage", SendMessageOptions.DontRequireReceiver); base.gameObject.SendMessage("HasAppliedDamage", SendMessageOptions.DontRequireReceiver); } if (flag2) { base.transform.position = this.prevPosition; base.transform.rotation = this.prevRotation; this.arrowHeadRB.velocity = this.prevVelocity; Physics.IgnoreCollision(this.arrowHeadRB.GetComponent <Collider>(), collision.collider); Physics.IgnoreCollision(this.shaftRB.GetComponent <Collider>(), collision.collider); } if (flag) { this.StickInTarget(collision, this.travelledFrames < 2); } if (Player.instance && collision.collider == Player.instance.headCollider) { Player.instance.PlayerShotSelf(); } } }
//------------------------------------------------- void OnCollisionEnter(Collision collision) { if (inFlight) { Rigidbody rb = GetComponent <Rigidbody>(); float rbSpeed = rb.velocity.sqrMagnitude; bool canStick = (targetPhysMaterial != null && collision.collider.sharedMaterial == targetPhysMaterial && rbSpeed > 0.2f); bool hitBalloon = collision.collider.gameObject.GetComponent <Balloon>() != null; if (travelledFrames < 2 && !canStick) { // Reset transform but halve your velocity transform.position = prevPosition - prevVelocity * Time.deltaTime; transform.rotation = prevRotation; Vector3 reflfectDir = Vector3.Reflect(arrowHeadRB.velocity, collision.contacts[0].normal); arrowHeadRB.velocity = reflfectDir * 0.25f; shaftRB.velocity = reflfectDir * 0.25f; travelledFrames = 0; return; } if (glintParticle != null) { glintParticle.Stop(true); } // Only play hit sounds if we're moving quickly if (rbSpeed > 0.1f) { hitGroundSound.Play(); } FireSource arrowFire = gameObject.GetComponentInChildren <FireSource>(); FireSource fireSourceOnTarget = collision.collider.GetComponentInParent <FireSource>(); if (arrowFire != null && arrowFire.isBurning && (fireSourceOnTarget != null)) { if (!hasSpreadFire) { collision.collider.gameObject.SendMessageUpwards("FireExposure", gameObject, SendMessageOptions.DontRequireReceiver); hasSpreadFire = true; } } else { // Only count collisions with good speed so that arrows on the ground can't deal damage // always pop balloons if (rbSpeed > 0.1f || hitBalloon) { collision.collider.gameObject.SendMessageUpwards("ApplyDamage", SendMessageOptions.DontRequireReceiver); gameObject.SendMessage("HasAppliedDamage", SendMessageOptions.DontRequireReceiver); } } if (hitBalloon) { // Revert my physics properties cause I don't want balloons to influence my travel transform.position = prevPosition; transform.rotation = prevRotation; arrowHeadRB.velocity = prevVelocity; Physics.IgnoreCollision(arrowHeadRB.GetComponent <Collider>(), collision.collider); Physics.IgnoreCollision(shaftRB.GetComponent <Collider>(), collision.collider); } if (canStick) { StickInTarget(collision, travelledFrames < 2); } // Player Collision Check (self hit) if (Player.instance && collision.collider == Player.instance.headCollider) { Player.instance.PlayerShotSelf(); } } }