Skip to content
Snippets Groups Projects

Draft: Improve walking implementation

Closed Jan Delember requested to merge feature/improve-walking into 4.26
All threads resolved!
2 files
+ 25
12
Compare changes
  • Side-by-side
  • Inline

Files

@@ -22,7 +22,7 @@ UVRPawnMovement::UVRPawnMovement(const FObjectInitializer& ObjectInitializer) :
@@ -22,7 +22,7 @@ UVRPawnMovement::UVRPawnMovement(const FObjectInitializer& ObjectInitializer) :
void UVRPawnMovement::BeginPlay()
void UVRPawnMovement::BeginPlay()
{
{
Super::BeginPlay();
Super::BeginPlay();
LastCapsulePosition = FVector(0,0,0);
LastCapsulePosition.Reset();
LastSteeringCollisionVector = FVector(0,0,0);
LastSteeringCollisionVector = FVector(0,0,0);
}
}
@@ -42,6 +42,12 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F
@@ -42,6 +42,12 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F
ConsumeInputVector();
ConsumeInputVector();
AddInputVector(InputVector);
AddInputVector(InputVector);
}
}
 
 
const FVector CapsuleLocation = CapsuleColliderComponent->GetComponentLocation();
 
if(bDeactivatedWhileInCollision && !CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit)
 
{
 
bDeactivatedWhileInCollision=false;
 
}
if(NavigationMode == EVRNavigationModes::NAV_FLY || NavigationMode == EVRNavigationModes::NAV_WALK)
if(NavigationMode == EVRNavigationModes::NAV_FLY || NavigationMode == EVRNavigationModes::NAV_WALK)
{
{
@@ -61,7 +67,7 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F
@@ -61,7 +67,7 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F
MoveByGravityOrStepUp(DeltaTime);
MoveByGravityOrStepUp(DeltaTime);
//if we physically (in the tracking space) walked into something, move the world away (by moving the pawn)
//if we physically (in the tracking space) walked into something, move the world away (by moving the pawn)
CheckForPhysWalkingCollision();
if(!bDeactivatedWhileInCollision) CheckForPhysWalkingCollision();
}
}
if(NavigationMode == EVRNavigationModes::NAV_NONE)
if(NavigationMode == EVRNavigationModes::NAV_NONE)
@@ -130,15 +136,15 @@ void UVRPawnMovement::SetCapsuleColliderToUserSize()
@@ -130,15 +136,15 @@ void UVRPawnMovement::SetCapsuleColliderToUserSize()
void UVRPawnMovement::CheckForPhysWalkingCollision()
void UVRPawnMovement::CheckForPhysWalkingCollision()
{
{
if(LastCapsulePosition.IsNearlyZero())
if(!LastCapsulePosition.IsSet())
{
{
//probably not yet set, so do nothing than setting it
//not yet set, so do nothing than setting it
LastCapsulePosition = CapsuleColliderComponent->GetComponentLocation();
LastCapsulePosition = CapsuleColliderComponent->GetComponentLocation();
return;
return;
}
}
const FVector CapsuleLocation = CapsuleColliderComponent->GetComponentLocation();
const FVector CapsuleLocation = CapsuleColliderComponent->GetComponentLocation();
const FHitResult HitResult = CreateCapsuleTrace(LastCapsulePosition, CapsuleLocation);
const FHitResult HitResult = CreateCapsuleTrace(LastCapsulePosition.GetValue(), CapsuleLocation);
//if this was not possible move the entire pawn away to avoid the head collision
//if this was not possible move the entire pawn away to avoid the head collision
if (HitResult.bBlockingHit)
if (HitResult.bBlockingHit)
@@ -147,13 +153,17 @@ void UVRPawnMovement::CheckForPhysWalkingCollision()
@@ -147,13 +153,17 @@ void UVRPawnMovement::CheckForPhysWalkingCollision()
//move it out twice as far, to avoid getting stuck situations
//move it out twice as far, to avoid getting stuck situations
UpdatedComponent->AddWorldOffset(2*MoveOutVector);
UpdatedComponent->AddWorldOffset(2*MoveOutVector);
}
}
else
 
 
//only update if not in collision
 
if(!CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit)
{
{
//only update if not in collision
LastCapsulePosition = CapsuleColliderComponent->GetComponentLocation();;
if(!CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit)
}
{
else{
LastCapsulePosition = CapsuleLocation;
//we are still in collision, so deactivate collision handling until this stopped
}
bDeactivatedWhileInCollision=true;
 
LastCapsulePosition.Reset();
}
}
}
}
Loading