I tried to make a mechanic that makes the player Springboard off Obstacle, just like in MEC (Mirror’s Edge: Catalyst), but it just keeps “dragging me down”, instead to the top of the obstacle.
How does Springboard works?
Springboarding triggers, when player Holds Jump Input, when facing the obstacle (jumping towards obstacle, while Sprinting). It takes player to reach the top of obstacle in about 0,5 seconds, before jumping off it, boosting jump.
Code Snippets:
float BFP_ODS_GetDST_ToObstacle()
{
bool Debug_Distance = true;
// Calculate the distance between Player's Position and Obstacle
float LV_DST_Obstacle = FVector::Dist(PlayerLoc_Current, ELS_ODS_ObstacleLocTop);
if (Debug_Distance)
{
if (LV_DST_Obstacle <= ELS_ODS_Face_Distance)
{
GEngine->AddOnScreenDebugMessage(-1, 0.f, FColor::Green, FString::Printf(TEXT("Distance to obstacle: %f"), ELS_ODS_DST_ToObstacle));
}
}
return LV_DST_Obstacle;
}
void BPF_MACT_PerformHACT_Jump()
{
// Check if the obstacle top is valid
if (!ELS_ODS_ObstacleLocTop.IsZero())
{
if (ELS_ODS_DST_ToObstacle > ELS_ODS_RangeVault && ELS_ODS_DST_ToObstacle < ELS_ODS_RangeSpringboard)
{
if (MoveState_IsSprinting)
{
BPF_MACT_SpringboardStart();
}
}
}
}
void BPF_MACT_SpringboardStart()
{
ELS_ODS_DST_ToObstacle = BFP_ODS_GetDST_ToObstacle();
ELS_Mvnt_Action_Current = ECndCharacter_MovementAction::MAC_Springboarding;
ELS_Mvnt_State_Current = ECndCharacter_MovementState::MSTE_Springboarding;
MoveState_CanDive = false;
// Calculate the distance to the obstacle top (using the updated distance)
float DistanceToObstacle = FVector::Dist(PlayerLoc_Current, ELS_ODS_ObstacleLocTop);
// Calculate the time to target dynamically based on the distance
float TimeToTarget = FMath::Max(0.25f, DistanceToObstacle / 500.0f); // Adjust the divisor for speed control
// Calculate the jump velocity
FVector JumpVelocity = BFP_ODS_CalculateJumpVelocity(PlayerLoc_Current, ELS_ODS_ObstacleLocTop, -GetWorld()->GetGravityZ(), TimeToTarget);
// Apply jump velocity to the player character
CndPlayerCharacter->LaunchCharacter(JumpVelocity, true, true);
}
FVector BFP_ODS_CalculateJumpVelocity(FVector StartPoint, FVector EndPoint, float Gravity, float TimeToTarget)
{
FVector Delta = EndPoint - StartPoint;
FVector JumpVelocity = Delta / TimeToTarget - 0.5f * FVector(0, 0, -Gravity) * TimeToTarget; // Note the negative sign for gravity
return JumpVelocity;
}
QUOTE:
Thanks, I needed it for my “game” that’ll never see it’s daylight.
Moments later: Why isn’t it working?