Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected virtual void OnCollisionEnter(Collision collision)
- {
- if (collision.impulse == Vector3.zero)
- return;
- Vector3 previousAvgVelocity = avgVelocity;
- if (printCollision && isDamaging && Time.time - lastDamageTime > 0.15f)
- {
- VRLog.Log(name + " Collision with " + collision.rigidbody.gameObject.name + " relative velocity " + collision.relativeVelocity + " ( " + collision.relativeVelocity.magnitude + " ) tracked velocity " + trackedVelocity + " ( " + trackedVelocity.magnitude + " ) rigidbody velocity " + GetComponent<Rigidbody>().velocity + " ( " + GetComponent<Rigidbody>().velocity.magnitude + " ) average velocity " + avgVelocity + " ( " + avgVelocity.magnitude + ")");
- }
- if (minimumDamageVelocity > 0f)
- {
- if (avgVelocity.magnitude < minimumDamageVelocity)
- return;
- }
- if (weaponBase != null && weaponBase.grabbedByHand != null)
- {
- weaponBase.grabbedByHand.HitSomething(collision.relativeVelocity - velocity, collision.gameObject);
- }
- else if (GetComponentInParent<Fist>() != null)
- {
- GetComponentInParent<Fist>().VibrateControllerPulse((collision.relativeVelocity - velocity).magnitude * 0.05f, 0.4f);
- }
- if (collision.rigidbody != null && isDamaging)
- {
- var db = collision.rigidbody.GetComponent<DamageRelay>();
- if (isPlayerFist && db != null && db.GetComponent<SeverableLimb>() != null && db.GetComponent<SeverableLimb>().armorPiece != null)
- {
- db = db.GetComponent<SeverableLimb>().armorPiece;
- }
- Vector3 relativeVel = collision.relativeVelocity;
- if (addKinematicVelocity)
- {
- relativeVel -= velocity;
- }
- if (avgVelocity.y > 0f && damageType != DamageType.Stab && damageType != DamageType.Cut)
- {
- avgVelocity.y *= 1.5f;
- if (isHeavy)
- avgVelocity.y *= 2f;
- }
- if (!IsThisGameObjectMyWielder(db))
- {
- if (db != null)
- {
- if (db != null && Time.time - lastDamageTime > 0.15f)
- {
- lastDamageTime = Time.time;
- Vector3 damage = scaleDamage * relativeVel;
- Vector3 hitNormal = Vector3.Cross(transform.forward, avgVelocity);
- if (db.GetComponent<PlayerDamageRelay>() == null)
- {
- if (damageType == DamageType.Stab && !db.IsArmorPiece)
- {
- if (Vector3.Dot(avgVelocity.normalized, transform.forward) > 0.5f)
- {
- Impale(db, collision.contacts[0].point);
- }
- else
- {
- VRLog.Log("averagevelocity not correct: " + avgVelocity.normalized + ", " + transform.forward);
- return;
- }
- }
- if (bonusVelocity != 0f)
- {
- var totalBonusVelocity = bonusVelocity + (IsWieldedByPlayer() ? playerWieldedBonusVelocity : 0f);
- //print("Relative vel: " + relativeVel + ", avg: " + avgVelocity + ", " + collision.rigidbody.gameObject.name);
- if (db.IsArmorPiece)
- {
- if (!db.GetComponent<ArmorPiece>().detached)
- {
- db.GetComponent<ArmorPiece>().armoredTo.rigidbody.AddForceAtPosition(-relativeVel * totalBonusVelocity * 0.5f, collision.contacts[0].point, ForceMode.VelocityChange);
- if (isHeavy)
- {
- db.GetComponent<ArmorPiece>().armoredTo.owner.chest.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.25f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<ArmorPiece>().armoredTo.owner.lowerChest.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.25f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<ArmorPiece>().armoredTo.owner.pelvis.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.25f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<ArmorPiece>().armoredTo.owner.Damage(damage.magnitude / 10f, 0f, this.gameObject, damageType);
- }
- else
- {
- db.GetComponent<ArmorPiece>().armoredTo.owner.chest.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.25f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<ArmorPiece>().armoredTo.owner.lowerChest.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.25f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<ArmorPiece>().armoredTo.owner.pelvis.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.25f, collision.contacts[0].point, ForceMode.VelocityChange);
- }
- }
- }
- else
- {
- collision.rigidbody.AddForceAtPosition(-relativeVel * totalBonusVelocity * 0.5f, collision.contacts[0].point, ForceMode.VelocityChange);
- if ((weaponBase != null || isPlayerFist))
- {
- Vector3 actualVel = GetComponent<Rigidbody>().velocity + velocity;
- db.GetComponent<SeverableLimb>().owner.chest.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.35f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<SeverableLimb>().owner.lowerChest.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.35f, collision.contacts[0].point, ForceMode.VelocityChange);
- db.GetComponent<SeverableLimb>().owner.pelvis.GetComponent<Rigidbody>().AddForceAtPosition(avgVelocity * totalBonusVelocity * 0.35f, collision.contacts[0].point, ForceMode.VelocityChange);
- }
- }
- }
- }
- DoDamage();
- db.Damage(damageType, damage, collision.contacts[0].point, this.gameObject, hitNormal, collision);
- }
- }
- else if (collision.rigidbody.GetComponent<WeaponImpactSound>() != null)
- {
- if (collision.rigidbody.GetComponent<DamagerRigidbody>() != null && !HasSameWielder(collision.rigidbody.GetComponent<DamagerRigidbody>()) && Time.time - lastDamageTime > 0.15f)
- {
- lastDamageTime = Time.time + 0.1f;
- if (GetComponent<Rigidbody>() != null)
- {
- GetComponent<Rigidbody>().AddForce(relativeVel * 0.9f, ForceMode.VelocityChange);
- }
- if (collision.rigidbody.GetComponent<DamagerRigidbody>().weaponBase != null)
- {
- bool byPlayer = false;
- if (isPlayerFist)
- byPlayer = true;
- else if (weaponBase != null && weaponBase.wieldedByPlayer)
- byPlayer = true;
- if (byPlayer)
- collision.rigidbody.GetComponent<DamagerRigidbody>().weaponBase.RecoilArm(-relativeVel * 0.75f, collision.contacts[0].point, byPlayer, this);
- }
- if (collision.rigidbody.GetComponent<DamagableShield>() != null)
- {
- //print(name + " damaging shield");
- collision.rigidbody.GetComponent<DamagableShield>().Damage(collision, velocity, scaleDamage * relativeVel, damageType, isHeavy);
- }
- }
- }
- else if (GetComponent<FisticuffFist>() != null && collision.rigidbody.GetComponent<DamagerRigidbody>() != null && collision.rigidbody.GetComponent<DamagerRigidbody>().isPlayerFist)
- {
- GetComponent<FisticuffFist>().owner.AI.InterruptAttack();
- }
- }
- }
- avgVelocity = previousAvgVelocity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement