//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); } } } } }
/// <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 Movement() { if (!_swinging && !_falling) { _controller.Move(Inputs.MoveInput * speed * _deltaTime); } if (Inputs.Jump && _jumpNumber > 0) { if (_head != null) { _jumpNumber--; JumpEvent?.Invoke(transform.position); _head.Hit(5, Vector3.up * jump, head.position); _landed = false; } } if (!_falling && _controller.isGrounded) { _jumpNumber = 1; } }
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 * } * } */ } }