attack flow - breaking and blocking input, roll improvements

This commit is contained in:
2025-09-10 12:33:13 +02:00
parent 9d6c237088
commit 058920055b
9 changed files with 1219 additions and 491 deletions

View File

@@ -18,10 +18,6 @@ namespace Beyond
public bool useAnimationBasedRotation = false;
[Header("Beyond's Strafe Combat Settings")]
[Tooltip("The minimum horizontal input value to trigger a side roll instead of a forward/backward one.")]
[Range(0.1f, 1.0f)]
public float strafeRollInputThreshold = 0.3f;
[Tooltip("The name of the animation state to play when rolling forward while strafing. (This is now disabled)")]
public string strafeRollForwardAnim = "Roll_Forward"; // Kept for reference, but won't be used
[Tooltip("The name of the animation state to play when rolling backward while strafing.")]
@@ -31,15 +27,19 @@ namespace Beyond
[Tooltip("The name of the animation state to play when rolling right while strafing.")]
public string strafeRollRightAnim = "Roll_Right";
// --- UPDATED FIELDS FOR INDEPENDENT CONTROL ---
// --- UPDATED FIELDS FOR FINER CONTROL ---
[Header("Beyond's Strafe Roll Correction")]
[Tooltip("The fixed angle to rotate the character before a LEFT strafe roll.")]
[Range(0f, 90f)]
public float strafeRollLeftCorrectionAngle = 45f;
[Tooltip("An additional angle to apply for a LEFT strafe roll.")]
[Range(-90f, 90f)]
public float strafeRollLeftCorrectionAngle = -45f;
[Tooltip("The fixed angle to rotate the character before a RIGHT strafe roll.")]
[Range(0f, 90f)]
public float strafeRollRightCorrectionAngle = 70f;
[Tooltip("An additional angle to apply for a RIGHT strafe roll.")]
[Range(-90f, 90f)]
public float strafeRollRightCorrectionAngle = 45f;
[Tooltip("An additional angle to apply for a BACKWARD strafe roll. Use 0 for a standard 180-degree roll.")]
[Range(-180f, 180f)]
public float strafeRollBackwardCorrectionAngle = 0f;
// --- END OF UPDATED FIELDS ---
public bool GodMode
@@ -64,27 +64,21 @@ namespace Beyond
protected override void RollBehavior()
{
// If we are not strafing, use the default Invector roll behavior.
if (!isStrafing)
{
base.RollBehavior();
return;
}
// Custom Strafe Roll with Root Motion (no rotation logic needed here anymore)
if (!isRolling)
{
return;
}
Vector3 deltaPosition = new Vector3(animator.deltaPosition.x, 0f, animator.deltaPosition.z);
Vector3 v = (deltaPosition / Time.deltaTime) * (1f - stopMoveWeight);
if (rollUseGravity && animator.GetNormalizedTime(baseLayer) >= rollUseGravityTime)
{
v.y = _rigidbody.linearVelocity.y;
}
_rigidbody.linearVelocity = v;
}
@@ -120,7 +114,12 @@ namespace Beyond
}
}
// --- MODIFIED METHOD WITH TWO-ANGLE LOGIC ---
// --- FINAL ROBUST METHOD ---
// This logic now handles all specified cases:
// 1. Sets a base rotation facing the camera to ensure consistency.
// 2. Defaults to a backward roll if input is near-zero (fixing the lingering roll issue).
// 3. Never uses the forward roll; it triggers a backward roll instead.
// 4. Applies a unique correction angle for backward rolls as well as side rolls.
private void TriggerStrafeRoll(string forwardAnim, string backwardAnim, string leftAnim, string rightAnim)
{
OnRoll.Invoke();
@@ -129,42 +128,59 @@ namespace Beyond
currentStaminaRecoveryDelay = 2f;
string animToPlay;
float correctionAngle = 0f;
// Prioritize side rolls based on horizontal input.
if (Mathf.Abs(horizontalSpeed) > strafeRollInputThreshold)
// Determine the base "forward" direction from the camera, ignoring vertical tilt.
Vector3 baseForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
if (baseForward == Vector3.zero) baseForward = transform.forward; // Fallback
// Set the character's rotation to this base direction. This provides a clean slate.
transform.rotation = Quaternion.LookRotation(baseForward);
// Check if input is negligible (joystick is centered).
// input.sqrMagnitude is more efficient than input.magnitude. 0.1*0.1=0.01.
if (input.sqrMagnitude < 0.01f)
{
float correction = 0f;
// Check if rolling right (positive horizontal speed)
if (horizontalSpeed > 0)
{
animToPlay = rightAnim;
// For a right roll, we apply a negative rotation (turn left) to angle the trajectory forward.
correction = -strafeRollRightCorrectionAngle;
}
// Otherwise, rolling left
else
{
animToPlay = leftAnim;
// For a left roll, we apply a positive rotation (turn right) to angle the trajectory forward.
correction = strafeRollLeftCorrectionAngle;
}
// Apply the calculated rotation instantly around the Y-axis.
if (correction != 0)
{
transform.Rotate(0, correction, 0);
}
// If no input, always perform a backward roll.
animToPlay = backwardAnim;
correctionAngle = strafeRollBackwardCorrectionAngle;
}
// If horizontal input is not met, default to the backward roll.
else
{
animToPlay = backwardAnim;
// If there IS input, determine the dominant direction.
if (Mathf.Abs(verticalSpeed) >= Mathf.Abs(horizontalSpeed))
{
// Vertical input is dominant.
// ALWAYS use the backward roll, regardless of forward or backward input.
animToPlay = backwardAnim;
correctionAngle = strafeRollBackwardCorrectionAngle;
}
else
{
// Horizontal input is dominant.
if (horizontalSpeed > 0)
{
animToPlay = rightAnim;
correctionAngle = strafeRollRightCorrectionAngle;
}
else
{
animToPlay = leftAnim;
correctionAngle = strafeRollLeftCorrectionAngle;
}
}
}
// Apply the chosen correction angle if it's not zero.
if (correctionAngle != 0f)
{
transform.Rotate(0, correctionAngle, 0);
}
// Play the selected animation.
animator.CrossFadeInFixedTime(animToPlay, rollTransition, baseLayer);
}
// --- END OF MODIFIED METHOD ---
// --- END OF FINAL METHOD ---
public void OnEvadeStart() { if (!m_GodMode) isImmortal = true; }
public void OnEvadeEnd() { if (!m_GodMode) isImmortal = false; }