Skip to content
Snippets Groups Projects
Commit e7749a4f authored by Jonathan Ehret's avatar Jonathan Ehret
Browse files

fix(collision handling movement) allow to deativate the collision detection in...

fix(collision handling movement) allow to deativate the collision detection in case users manage to get stuck in something. In this case virtual steering is disabled but also physical collision checks so users can move out of the collision
parent 0e414ef8
No related branches found
No related tags found
2 merge requests!80UE5.3-2023.1-rc2,!70Physial Walking Fixes
Pipeline #343412 passed
......@@ -67,7 +67,14 @@ void UCollisionHandlingMovement::TickComponent(float DeltaTime, enum ELevelTick
}
}
// in case we are in a collision and collision checks are temporarily deactivated, we only allow physical
// movement without any checks, otherwise check collision during physical movement
if (bCollisionChecksTemporarilyDeactivated)
{
ConsumeInputVector();
}
else
{
// so we add stepping-up (for both walk and fly)
// and gravity for walking only
MoveByGravityOrStepUp(DeltaTime);
......@@ -75,6 +82,7 @@ void UCollisionHandlingMovement::TickComponent(float DeltaTime, enum ELevelTick
// if we physically (in the tracking space) walked into something, move the world away (by moving the pawn)
CheckForPhysWalkingCollision();
}
}
if (NavigationMode == EVRNavigationModes::NAV_NONE)
{
......@@ -150,6 +158,7 @@ void UCollisionHandlingMovement::CheckAndRevertCollisionSinceLastTick()
if (!CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit)
{
LastCollisionFreeCapsulePosition = CapsuleLocation;
bCollisionChecksTemporarilyDeactivated = false;
}
return;
}
......@@ -157,8 +166,17 @@ void UCollisionHandlingMovement::CheckAndRevertCollisionSinceLastTick()
// check whether we are in a collision at the current position
if (CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit)
{
// if so move back to last position
UpdatedComponent->AddWorldOffset(LastCollisionFreeCapsulePosition.GetValue() - CapsuleLocation);
// if so move back to last position, but only if that position is still collision free
// since the user might have moveed physically in between
FVector LastCapsulePos = LastCollisionFreeCapsulePosition.GetValue();
if (!CreateCapsuleTrace(LastCapsulePos, LastCapsulePos).bBlockingHit)
{
UpdatedComponent->AddWorldOffset(LastCapsulePos - CapsuleLocation);
}
else
{
bCollisionChecksTemporarilyDeactivated = true;
}
}
else
{
......@@ -175,6 +193,13 @@ void UCollisionHandlingMovement::MoveOutOfNewDynamicCollisions()
FVector ResolveDirection = 1.5f * ResolveDirectionOptional.GetValue(); // scale it up for security distance
UpdatedComponent->AddWorldOffset(ResolveDirection);
// check whether this helped in resolving the collision, and if not deactivate collision checks temporarily
if (CreateCapsuleTrace(UpdatedComponent->GetComponentLocation(), UpdatedComponent->GetComponentLocation())
.bBlockingHit)
{
bCollisionChecksTemporarilyDeactivated = true;
}
// invalidate the last collision-free position, since apparently something changed so we got into this collision
LastCollisionFreeCapsulePosition.Reset();
}
......@@ -195,8 +220,8 @@ void UCollisionHandlingMovement::CheckForPhysWalkingCollision()
if (HitResult.bBlockingHit)
{
const FVector MoveOutVector = HitResult.Location - CapsuleLocation;
// move it out twice as far, to avoid getting stuck situations
UpdatedComponent->AddWorldOffset(2 * MoveOutVector);
// move it out a bit farther, to avoid getting stuck situations
UpdatedComponent->AddWorldOffset(1.2f * MoveOutVector);
}
}
......
......@@ -85,4 +85,8 @@ private:
// just stored for performance gains;
UPROPERTY(VisibleAnywhere, Transient, DuplicateTransient)
TArray<AActor*> ActorsToIgnore;
// if a collision happens and cannot be resolved (e.g. the user crouched, walked under something and stood up)
// we remporarily deactivate all checks until the user is in a collision free situation again
bool bCollisionChecksTemporarilyDeactivated = false;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment