//public void Punch(bool isLeftHand) public void Punch(int _left) { Transform hand = _left == 1 ? leftHand : rightHand; //Transform hand = isLeftHand == true ? leftHand : rightHand; DebugExtension.DebugWireSphere(hand.position, punchRadius, punchRadius); RaycastHit[] hits = Physics.SphereCastAll(hand.position, punchRadius, hand.forward, 0f); //Collider[] hitColliders = Physics.OverlapSphere(hand.position, punchRadius); List <PlayerController> playersHit = new List <PlayerController>(); foreach (var hit in hits) { RootFix playerRoot = hit.transform.GetComponent <RootFix>(); if (playerRoot != null) { PlayerController player = playerRoot.playerRoot.GetComponentInChildren <PlayerController>(); DamageableBehaviour damageable = playerRoot.playerRoot.GetComponent <DamageableBehaviour>(); var myAlignment = myDamageableBehaviour.configuration.AlignmentProvider; if (damageable != null && myAlignment != null) { float knockback = 1f + (damageable.configuration.CurrentDamage / 100f); //EDIT var hitInfo = new HitInfo { damageChangeInfo = new DamageChangeInfo(), damagePoint = hit.point }; bool canKnockBack = (myAlignment != damageable.configuration.AlignmentProvider); if (!playersHit.Contains(player)) { if (canKnockBack) { damageable.configuration.AddDamage(damagePerHit, hitInfo); playersHit.Add(player); } } MuscleCollisionBroadcaster broadcaster = hit.transform.GetComponent <MuscleCollisionBroadcaster>(); if (broadcaster != null && canKnockBack) { Vector3 heading = hit.point - hand.position; Vector3 direction = hand.transform.forward; broadcaster.Hit(5, direction * (baseKnockback * (knockback * (damageable.configuration.CurrentDamage / 100f))), hit.point); } } } } }
// When a muscle collides with something (called by the MuscleCollisionBroadcaster component on the muscle). protected override void OnMuscleCollisionBehaviour(MuscleCollision m) { // All the conditions for ignoring this if (!enabled) return; if (state == State.Unpinned) return; if (collisions > maxCollisions) return; if (!LayerMaskExtensions.Contains(collisionLayers, m.collision.gameObject.layer)) return; if (masterProps.normalMode == NormalMode.Kinematic && !puppetMaster.isActive && !masterProps.activateOnStaticCollisions && m.collision.gameObject.isStatic) return; // Get the collision impulse on the muscle float impulse = GetImpulse(m); if (impulse <= 0f) return; collisions ++; // Try to find out if it collided with another puppet's muscle if (m.collision.collider.attachedRigidbody != null) { broadcaster = m.collision.collider.attachedRigidbody.GetComponent<MuscleCollisionBroadcaster>(); if (broadcaster != null) { if (broadcaster.muscleIndex < broadcaster.puppetMaster.muscles.Length) { // Multiply impulse (if the other muscle has been boosted) impulse *= broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].state.impulseMlp; float stayF = m.isStay? 0.05f: 0.1f; broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].offset -= m.collision.impulse * Time.deltaTime * stayF; /* float velocityF = puppetMaster.muscles[m.muscleIndex].rigidbody.velocity.sqrMagnitude / broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].rigidbody.velocity.sqrMagnitude; velocityF = Mathf.Clamp(velocityF, 0.5f, 2f); //velocityF = 1f + (velocityF - 1f) * 0.5f; impulse /= velocityF; */ } } } // Should we activate the puppet? if (Activate(m.collision, impulse)) puppetMaster.mode = PuppetMaster.Mode.Active; // Let other scripts know about the collision if (OnCollisionImpulse != null) OnCollisionImpulse(m, impulse); // Unpin the muscle (and other muscles) UnPin(m.muscleIndex, impulse); }
/// <summary> /// Triggers the Ragdoll behaviour of the NPC /// </summary> /// <param name="col">Collider that was hit</param> public void TriggerPuppetMaster(Collider col, float impactForce, Vector3 impactPosition, float unpin) { // Check for Muscles MuscleCollisionBroadcaster broadcaster = col.attachedRigidbody.GetComponent <MuscleCollisionBroadcaster>(); // Apply HIT-Force to the given Collider if (broadcaster) { // NPC Drops Dead puppetMaster.mode = PuppetMaster.Mode.Active; puppetMaster.state = PuppetMaster.State.Dead; puppetMaster.pinWeight = 0; // Process with Force broadcaster.Hit(unpin, (col.gameObject.transform.position - impactPosition) * impactForce, impactPosition); } // Disable Behavior and Controller GetComponent <BehaviorDesigner.Runtime.Behavior>().enabled = false; GetComponent <Pathfinding.RVO.RVOController>().enabled = false; }
private void Start() { if (root == null) { root = transform.root; } myDamageableBehaviour = GetComponentInParent <DamageableBehaviour>(); FindObjectOfType <UIManager>().Join(myDamageableBehaviour); //Debug.Log(string.Format("Component In Parent = {0}", myDamageableBehaviour.name)); _controller = GetComponent <CharacterController>(); _animator = GetComponent <Animator>(); FindObjectOfType <PauseMenu>().Menu += Menu; FindObjectOfType <EffectsManager>().Subscribe(myDamageableBehaviour); if (head != null) { _head = head.GetComponent <MuscleCollisionBroadcaster>(); _jumpNumber = 1; } }
// When a muscle collides with something (called by the MuscleCollisionBroadcaster component on the muscle). protected override void OnMuscleCollisionBehaviour(MuscleCollision m) { if (OnCollision != null) { OnCollision(m); } // All the conditions for ignoring this if (!enabled) { return; } if (state == State.Unpinned) { return; } if (collisions > maxCollisions) { return; } if (!LayerMaskExtensions.Contains(collisionLayers, m.collision.gameObject.layer)) { return; } if (masterProps.normalMode == NormalMode.Kinematic && !puppetMaster.isActive && !masterProps.activateOnStaticCollisions && m.collision.gameObject.isStatic) { return; } // Get the collision impulse on the muscle float cT = collisionThreshold; float impulse = GetImpulse(m, ref cT); float minImpulseMlp = PuppetMasterSettings.instance != null? (1f + PuppetMasterSettings.instance.currentlyActivePuppets * PuppetMasterSettings.instance.activePuppetCollisionThresholdMlp): 1f; float minImpulse = cT * minImpulseMlp; if (impulse <= minImpulse) { return; } collisions++; // Try to find out if it collided with another puppet's muscle if (m.collision.collider.attachedRigidbody != null) { broadcaster = m.collision.collider.attachedRigidbody.GetComponent <MuscleCollisionBroadcaster>(); if (broadcaster != null) { if (broadcaster.muscleIndex < broadcaster.puppetMaster.muscles.Length) { // Multiply impulse (if the other muscle has been boosted) impulse *= broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].state.impulseMlp; //float stayF = m.isStay? 0.05f: 0.1f; //broadcaster.puppetMaster.muscles[broadcaster.muscleIndex].offset -= m.collision.impulse * Time.deltaTime * stayF; } } } // DO not move this up, the impulse value will be wrong. // Let other scripts know about the collision (even the ones below collision threshold) if (OnCollisionImpulse != null) { OnCollisionImpulse(m, impulse); } // Should we activate the puppet? if (Activate(m.collision, impulse)) { puppetMaster.mode = PuppetMaster.Mode.Active; } // Unpin the muscle (and other muscles) UnPin(m.muscleIndex, impulse); }
public void SwingHit() { DebugExtension.DebugWireSphere(swingLocation.position, swingRadius, 0.25f); //Delete this RaycastHit[] _hits = Physics.SphereCastAll(swingLocation.position, swingRadius, transform.forward, 0f); PickUp weapon = _item.GetComponent <PickUp>(); List <PlayerController> playersHit = new List <PlayerController>(); foreach (RaycastHit hit in _hits) { RootFix playerRoot = hit.transform.GetComponent <RootFix>(); if (playerRoot != null) { PlayerController player = playerRoot.playerRoot.GetComponentInChildren <PlayerController>(); DamageableBehaviour damageable = playerRoot.playerRoot.GetComponent <DamageableBehaviour>(); var myAlignment = myDamageableBehaviour.configuration.AlignmentProvider; if (damageable != null && myAlignment != null) { float knockback = 1f + (damageable.configuration.CurrentDamage / 100f); //EDIT var hitInfo = new HitInfo { damageChangeInfo = new DamageChangeInfo(), damagePoint = hit.point }; bool canKnockBack = (myAlignment != damageable.configuration.AlignmentProvider); //print("Obj: " + player.name + ", Count: " + playersHit.Count + ", Contains: " + playersHit.Contains(player)); if (!playersHit.Contains(player)) { if (canKnockBack) { damageable.configuration.AddDamage((weapon != null ? weapon.damage : damagePerHit), hitInfo); playersHit.Add(player); } } MuscleCollisionBroadcaster broadcaster = hit.transform.GetComponent <MuscleCollisionBroadcaster>(); if (broadcaster != null && canKnockBack) { broadcaster.Hit(5, rightHand.transform.forward * (baseKnockback * (knockback * (damageable.configuration.CurrentDamage / 100f))), hit.point); } } } /* * if (_hit.transform.root != transform.root) * { * Debug.Log("RUGHAARINMIJNRIETJE TWEE"); * * //PlayerController _player = null; * DamageableBehaviour _damageable = null; * IAlignmentProvider myAlignment = null; * * if (_hit.transform.root.tag == "Player") * { * //_player = _hit.transform.root.GetComponentInChildren<PlayerController>(); * _damageable = _hit.transform.root.GetComponentInChildren<DamageableBehaviour>(); * } * * float knockback = 1f; * if (_damageable != null) * { * myAlignment = myDamageableBehaviour.configuration.AlignmentProvider; * * int weaponDamagePerHit = ((_item != null) ? _item.GetComponent<PickUp>().damage : damagePerHit); * * _damageable.configuration.CheckDamage(weaponDamagePerHit, myAlignment, swingLocation.position); * } * * MuscleCollisionBroadcaster broadcaster = _hit.transform.GetComponent<MuscleCollisionBroadcaster>(); * * if (broadcaster != null && _damageable.CanKnockback(myAlignment)) * { * Vector3 _heading = _hit.point - swingLocation.position; * float _distance = _heading.magnitude; * Vector3 _direction = _heading / _distance; * * broadcaster.Hit(5, _direction * (baseKnockback * knockback), _hit.point); //Edit this * } * } */ } }