tengri/Source/TengriPlatformer/Movement/Collision/TengriCollisionResolver.h

95 lines
3.9 KiB
C++

// Request Games © All rights reserved
// Source/TengriPlatformer/Movement/Collision/TengriCollisionResolver.h
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "TengriPlatformer/Movement/Core/TengriMovementConfig.h"
#include "TengriPlatformer/Movement/Collision/TengriSweepResult.h"
#include "TengriCollisionResolver.generated.h"
class UCapsuleComponent;
/**
* Static collision resolution utilities for Tengri Movement System.
* Handles swept collision, wall sliding, step-up, and ground snapping.
*/
UCLASS()
class TENGRIPLATFORMER_API UTengriCollisionResolver : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
// ════════════════════════════════════════════════════════════════════
// MAIN RESOLUTION
// ════════════════════════════════════════════════════════════════════
/**
* Resolve movement with collision: slide along walls, step up obstacles.
* @param WorldContext - Object providing world context
* @param StartLocation - Starting position
* @param DesiredDelta - Desired movement this frame
* @param Capsule - Collision capsule
* @param Thresholds - Surface classification thresholds
* @param MaxStepHeight - Maximum step-up height
* @param MaxIterations - Maximum slide iterations
* @param bShowDebug - Enable debug visualization
* @return Final position and collision info
*/
static FTengriSweepResult ResolveMovement(
const UObject* WorldContext,
const FVector& StartLocation,
const FVector& DesiredDelta,
const UCapsuleComponent* Capsule,
const FSurfaceThresholds& Thresholds,
float MaxStepHeight,
int32 MaxIterations,
bool bShowDebug = false
);
// ════════════════════════════════════════════════════════════════════
// PRIMITIVES
// ════════════════════════════════════════════════════════════════════
/** Perform a simple capsule sweep from Start to End */
static FTengriSweepResult PerformSweep(
const UObject* WorldContext,
const FVector& Start,
const FVector& End,
const UCapsuleComponent* Capsule,
bool bShowDebug = false
);
/** Attempt to step up over an obstacle */
static bool StepUp(
const UObject* WorldContext,
const FVector& StartLocation,
const FVector& DesiredDelta,
const FHitResult& ImpactHit,
const UCapsuleComponent* Capsule,
float MaxStepHeight,
FVector& OutLocation
);
/** Snap character to ground surface below */
static bool SnapToGround(
const UObject* WorldContext,
const UCapsuleComponent* Capsule,
float SnapDistance,
const FSurfaceThresholds& Thresholds,
FVector& OutLocation,
FHitResult& OutHit
);
// ════════════════════════════════════════════════════════════════════
// VELOCITY MATH
// ════════════════════════════════════════════════════════════════════
/** Remove velocity component going into the surface */
static FVector ClipVelocity(const FVector& Velocity, const FVector& Normal);
/** Project velocity along surface, preserving magnitude */
static FVector ProjectVelocity(const FVector& Velocity, const FVector& Normal);
};