Skip to content
Snippets Groups Projects
Commit 7ddb21a2 authored by Ehret's avatar Ehret
Browse files

deactivate collision when it persists (e.g., because something of he...

deactivate collision when it persists (e.g., because something of he environment moved into us, like the rotation VCI logo)
parent 231356fb
Branches
No related tags found
2 merge requests!28Improve Walking implementation,!13Draft: Improve walking implementation
Pipeline #308667 failed
...@@ -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);
} }
...@@ -43,6 +43,12 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F ...@@ -43,6 +43,12 @@ void UVRPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, F
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)
{ {
if(InputVector.Size() > 0.001){ if(InputVector.Size() > 0.001){
...@@ -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 //only update if not in collision
if(!CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit) if(!CreateCapsuleTrace(CapsuleLocation, CapsuleLocation).bBlockingHit)
{ {
LastCapsulePosition = CapsuleLocation; LastCapsulePosition = CapsuleColliderComponent->GetComponentLocation();;
} }
else{
//we are still in collision, so deactivate collision handling until this stopped
bDeactivatedWhileInCollision=true;
LastCapsulePosition.Reset();
} }
} }
......
...@@ -76,9 +76,12 @@ private: ...@@ -76,9 +76,12 @@ private:
UPROPERTY() USceneComponent* HeadComponent = nullptr; UPROPERTY() USceneComponent* HeadComponent = nullptr;
float VerticalSpeed = 0.0f; float VerticalSpeed = 0.0f;
FVector LastCapsulePosition; TOptional<FVector> LastCapsulePosition;
FVector LastSteeringCollisionVector; FVector LastSteeringCollisionVector;
//this will deactivate all collision avoidance, so we can move out of a collision, e.g. if movements of the scene provoked a collision
bool bDeactivatedWhileInCollision = false;
//just stored for performance gains; //just stored for performance gains;
TArray<AActor*> ActorsToIgnore; TArray<AActor*> ActorsToIgnore;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment