private void ThrowWeapon() { // Throw it if (!inAir) { // ReSharper disable once Unity.InefficientPropertyAccess transform.parent = null; var mousePosition = Camera.ScreenToWorldPoint(Input.mousePosition); mousePosition.z = 0f; var direction = (mousePosition - Player.transform.position).normalized; Rigidbody2D.AddForce(direction * 380); PlayerRigidbody2D.AddForce(direction * 80); inAir = true; stuckInObject = false; stuckInFloor = false; returning = false; // Stop looking at the mouse when we throw it LookAtMouse.shouldLook = false; replacementObject.SetActive(true); firstStick = true; } }
protected override void OnBeHit(DamageBase damage) { if (Player.IsDefence) { return; } if (damage.AttackPolarity != Polarity.None) { Vector2 myPoistion2Target = (damage.AttackPosition - new Vector2(Player.transform.position.x, Player.transform.position.y)).normalized; if (damage.AttackPolarity != Player.PlayerPolarity) { PlayerRigidbody2D.AddForce(myPoistion2Target * damage.AttackForce * AttackForceCoefficient); } else { PlayerRigidbody2D.AddForce(-myPoistion2Target * damage.AttackForce * AttackForceCoefficient); } if (Player.OnBeHit != null) { Player.OnBeHit(damage); } } }
protected override void OnBeHit(DamageBase damage) { base.OnBeHit(damage); if (damage.AttackPolarity == Polarity.None) { Vector2 myPoistion2Target = (damage.AttackPosition - new Vector2(Player.transform.position.x, Player.transform.position.y)).normalized; PlayerRigidbody2D.AddForce(-myPoistion2Target * damage.AttackForce * AttackForceCoefficient); Player.OnBeHit?.Invoke(damage); } }
protected virtual void ReactionForce(PlayerBase enemy) { if (AttackDamage.AttackPolarity == Polarity.None) { return; } Vector2 myPoistion2Target = (new Vector2(enemy.transform.position.x, enemy.transform.position.y) - AttackDamage.AttackPosition).normalized; if (AttackDamage.AttackPolarity != enemy.PlayerPolarity) { PlayerRigidbody2D.AddForce(myPoistion2Target * AttackDamage.AttackForce * ReactionCoefficient); } else { PlayerRigidbody2D.AddForce(-myPoistion2Target * AttackDamage.AttackForce * ReactionCoefficient); } }
protected new void Update() { base.Update(); _knifePoint.transform.localPosition = _knifePointPosition; _handlePoint.transform.localPosition = _handlePointPosition; // It hit a thing if (stuckInObject || stuckInFloor) { if (stuckInObject) { transform.localPosition = _offset; if (firstStick) { firstStick = false; stuckObjectRigidBody.AddForce(stuckObject.transform.position - Player.transform.position * 14); } } // Pull it back // TODO: Maybe make it pull back by spinning around, like fishing if (Input.GetMouseButtonDown(0)) { transform.parent = null; if (stuckInObject) { stuckObject.transform.up = Vector3.zero; var direction = Player.transform.position - stuckObject.transform.position; stuckObjectRigidBody.AddForce(direction * 36); PlayerRigidbody2D.AddForce(direction * 20); } ImmobilizeEntity.UnstickEntity(); returning = true; } } else { if (MethodPassThrough.throwingWeapon) { MethodPassThrough.throwingWeapon = false; LookAtMouse.shouldLook = true; ThrowWeapon(); } } if (returning) { transform.position = Hand.transform.position + new Vector3(0, 0, 0.1f); transform.parent = Hand.transform; // replacementObject.SetActive(false); LookAtMouse.shouldLook = true; inAir = false; stuckInObject = false; stuckInFloor = false; } else { // It hit the floor if (!stuckInObject && Vector3.Distance(transform.position, Player.transform.position) > chainLength) { Rigidbody2D.velocity = Vector2.zero; inAir = false; stuckInObject = false; stuckInFloor = true; transform.rotation = new Quaternion(-3, 2, 0f, 0f); } } }