fgm24/Assets/Scripts/HeathSystem/RopeWhipAttack.cs

78 lines
2.4 KiB
C#
Raw Normal View History

//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...
*
2024-02-03 14:07:03 +01:00
public class RopeWhipAttack : MonoBehaviour
{
2024-02-04 05:40:23 +01:00
[SerializeField] PlayerAnimationHandler animationHandler;
2024-02-03 16:21:32 +01:00
[SerializeField] PlayerInput playerInput;
2024-02-03 14:07:03 +01:00
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;
2024-02-03 16:21:32 +01:00
if (playerInput.whipAttack)
2024-02-03 14:07:03 +01:00
{
2024-02-04 09:00:38 +01:00
otherPlayerAttack.joint.trailRenderer.enabled = true;
2024-02-04 05:40:23 +01:00
// 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);
2024-02-03 14:07:03 +01:00
joint.locked = true;
otherPlayerAttack.joint.body.drag = 0f;
}
else
{
2024-02-04 05:40:23 +01:00
animationHandler.Swing(false);
animationHandler.animator.speed = 1f;
animationHandler.animator.StopPlayback();
2024-02-03 14:07:03 +01:00
joint.locked = false;
2024-02-04 09:00:38 +01:00
otherPlayerAttack.joint.trailRenderer.enabled = false;
2024-02-03 14:07:03 +01:00
otherPlayerAttack.joint.body.drag = otherPlayerAttack.initialDrag;
}
}
2024-02-04 05:40:23 +01:00
float CalculateAngleBetwenRight()
{
Vector2 ropeDir = (otherPlayerAttack.joint.anchor.position - joint.anchor.position).normalized;
float angle = Vector2.SignedAngle(Vector2.right, ropeDir);
return angle;
}
2024-02-03 14:07:03 +01:00
}
*/