Dash function is called but doesn't change velocity

me and Bard ai just discussed this lol and Bard believes this maybe a good starting point for your function. I did not test it yet, but i will test eventually this week. At a glance you should be able to nest this function in as you need.

void ATBO02Character::DashForward(float DashDistance)
{
    FVector DashDirection = GetActorForwardVector();

    // Temporarily override max acceleration to ensure dash speed
    UCharacterMovementComponent* CharacterMovement = GetCharacterMovement();
    float OriginalMaxAcceleration = CharacterMovement->MaxAcceleration;
    CharacterMovement->MaxAcceleration = 10000.0f; // Adjust as needed

    // Calculate dash velocity based on distance and desired duration
    float DashDuration = 0.5f; // Adjust as desired
    float DashVelocity = DashDistance / DashDuration;

    // Apply impulse using AddImpulse for more control over acceleration
    CharacterMovement->AddImpulse(DashDirection * DashVelocity, true);

    // Restore original max acceleration after dash
    CharacterMovement->MaxAcceleration = OriginalMaxAcceleration;

    // Optionally clamp velocity to prevent excessive speed
    FVector CurrentVelocity = GetVelocity();
    if (CurrentVelocity.Size() > MaxDashSpeed)
    {
        SetVelocity(CurrentVelocity.GetSafeNormal() * MaxDashSpeed);
    }
}

Key aspects of this function:

  • Explicit Acceleration Override: Temporarily overrides MaxAcceleration to ensure the dash can achieve the desired velocity.
  • AddImpulse Usage: Uses AddImpulse for more granular control over acceleration, potentially avoiding issues with LaunchCharacter .
  • Velocity Calculation: Explicitly calculates dash velocity based on distance and duration, providing better control over the dash’s behavior.
  • Velocity Clamping: Optionally clamps velocity to a maximum value after the dash to prevent unintended overshoots.

Remember:

  • Adjust DashDistance , DashDuration , and MaxDashSpeed to match your specific gameplay requirements.

Blockquote