climbing mode polished

This commit is contained in:
2026-04-29 09:01:04 +02:00
parent 563df1ffc8
commit 74882e634b
3 changed files with 79 additions and 64 deletions

View File

@@ -19,6 +19,20 @@ void UCustomCharacterMovementComponent::PhysCustom(float DeltaTime, int32 Iterat
switch (CustomMovementMode)
{
case 0:
{
PhysClimbing(DeltaTime, Iterations);
break;
}
default:
// For any other custom mode, fallback to base implementation
Super::PhysCustom(DeltaTime, Iterations);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("Movement mode not implemented!"));
break;
}
}
void UCustomCharacterMovementComponent::PhysClimbing(float DeltaTime, int32 Iterations)
{
if (DeltaTime < MIN_TICK_TIME)
{
@@ -65,10 +79,20 @@ void UCustomCharacterMovementComponent::PhysCustom(float DeltaTime, int32 Iterat
UpdatedComponent->SetWorldLocation(NewLocation);
// Update Rotation
const FRotator TargetRotation = FRotationMatrix::MakeFromXZ(-SurfaceNormal, FVector::UpVector).Rotator();
FRotator TargetRotation = FRotationMatrix::MakeFromXZ(-SurfaceNormal, FVector::UpVector).Rotator();
if (TargetRotation.Pitch < -70.0f)
{
TargetRotation = FRotator(0.0f, UpdatedComponent->GetComponentRotation().Yaw, 0.0f);
UpdatedComponent->SetWorldRotation(TargetRotation);
SetMovementMode(MOVE_Falling);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Standing up"));
}
else
{
const FRotator NewRotation = FMath::RInterpTo(UpdatedComponent->GetComponentRotation(), TargetRotation, DeltaTime, 2.f);
UpdatedComponent->SetWorldRotation(NewRotation);
}
}
else
{
// Reset Rotation and set MovementMode to Falling
@@ -81,16 +105,6 @@ void UCustomCharacterMovementComponent::PhysCustom(float DeltaTime, int32 Iterat
{
Velocity = (UpdatedComponent->GetComponentLocation() - OldLocation) / DeltaTime;
}
break;
}
default:
// For any other custom mode, fallback to base implementation
Super::PhysCustom(DeltaTime, Iterations);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("Movement mode not implemented!"));
break;
}
}
void UCustomCharacterMovementComponent::OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode)

View File

@@ -21,6 +21,7 @@ public:
protected:
// Override PhysCustom to handle custom movement mode behaviors
virtual void PhysCustom(float DeltaTime, int32 Iterations) override;
void PhysClimbing(float DeltaTime, int32 Iterations);
virtual void OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode) override;
static bool SweepForwardForWall(const ACharacter* Character, FHitResult& OutHit, float SweepDistance = 100.f);
};