//using System.Collections; //using System.Collections.Generic; //using UnityEngine; //using UnityEngine.InputSystem; //using System.Linq; //using UnityUtils; /* * Screw this whip attack. Hard coded code. I hate it... * public class RopeWhipAttack : MonoBehaviour { [SerializeField] PlayerAnimationHandler animationHandler; [SerializeField] PlayerInput playerInput; public RopeWhipAttack otherPlayerAttack; public PlayerMovement playerMovement; public RopeJoint joint; public bool IsWhippingOtherPlayer => joint.locked; public bool IsBeingWhipped => otherPlayerAttack.joint.locked; public float initialDrag; private void Awake() { initialDrag = joint.body.drag; } private void Update() { // Other player is whip attacking if (otherPlayerAttack.joint.locked) return; if (playerInput.whipAttack) { otherPlayerAttack.joint.trailRenderer.enabled = true; // reset local scale so rotations match up transform.localScale = transform.localScale.With(x: 1f); animationHandler.Swing(true); animationHandler.animator.speed = 0f; float radianAngle = CalculateAngleBetwenRight(); float sign = Mathf.Sign(radianAngle); //if (sign < 0) // transform.localScale = transform.localScale.With(x: -1f); //else // transform.localScale = transform.localScale.With(x: 1f); float t = Mathf.Abs(radianAngle) / 360; if (sign > 0) t -= (radianAngle - 180) / 180 * sign; //Debug.Log($"angle: {radianAngle}, t: {t}, sgn: {sign}"); animationHandler.animator.Play("Swing", 0, t); joint.locked = true; otherPlayerAttack.joint.body.drag = 0f; } else { animationHandler.Swing(false); animationHandler.animator.speed = 1f; animationHandler.animator.StopPlayback(); joint.locked = false; otherPlayerAttack.joint.trailRenderer.enabled = false; otherPlayerAttack.joint.body.drag = otherPlayerAttack.initialDrag; } } float CalculateAngleBetwenRight() { Vector2 ropeDir = (otherPlayerAttack.joint.anchor.position - joint.anchor.position).normalized; float angle = Vector2.SignedAngle(Vector2.right, ropeDir); return angle; } } */