UCharacterMovementComponent::Swim
#include "GameFramework/CharacterMovementComponent.h"
Access: public
Description
Performs one swimming move by Delta and, if the character surfaces during the move, slides along the water line. Returns the fraction of the move that occurred above water.
Caveats & Gotchas
- • Gravity is still applied while swimming, just scaled by (1 - Buoyancy) per the header comment — Swim() does not disable gravity outright.
- • The returned airtime fraction is only non-zero when the character actually exits the water volume during this specific call; most calls while fully submerged simply return 0.
Signature
float Swim(FVector Delta, FHitResult& Hit) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Delta | FVector | Requested move while submerged. | — |
| Hit | FHitResult& | Out parameter populated with the hit result of the underwater move. | — |
Return Type
float Example
Advance an underwater move C++
void UMyCharacterMovementComponent::PhysSwimming(float deltaTime, int32 Iterations)
{
FHitResult Hit(1.f);
const float AirTime = Swim(Velocity * deltaTime, Hit);
if (AirTime > 0.f)
{
// Character surfaced partway through the move.
}
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?