Skip to content
Snippets Groups Projects
Commit 240e4625 authored by Ehret's avatar Ehret
Browse files

minor improvements

parent d45251bb
No related branches found
No related tags found
2 merge requests!28Improve Walking implementation,!13Draft: Improve walking implementation
......@@ -5,6 +5,8 @@
UVRPawnMovement::UVRPawnMovement(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// the capsule is used to store the players size and position, e.g., for other interactions and as starting point
// for the capsule trace (which however not use the capsule component directly)
CapsuleColliderComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleCollider"));
CapsuleColliderComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
CapsuleColliderComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
......@@ -131,18 +133,19 @@ void UVRPawnMovement::CheckForPhysWalkingCollision()
if(LastCapsulePosition.IsNearlyZero())
{
//probably not yet set, so do nothing than setting it
LastCapsulePosition = GetCapsuleLocationFromHead();
LastCapsulePosition = CapsuleColliderComponent->GetComponentLocation();
return;
}
const FVector CapsuleLocation = GetCapsuleLocationFromHead();
const FVector CapsuleLocation = CapsuleColliderComponent->GetComponentLocation();
const FHitResult HitResult = CreateCapsuleTrace(LastCapsulePosition, CapsuleLocation);
//if this was not possible move the entire pawn away to avoid the head collision
if (HitResult.bBlockingHit)
{
const FVector MoveOutVector = HitResult.Location-CapsuleLocation;
UpdatedComponent->AddWorldOffset(MoveOutVector);
//move it out twice as far, to avoid getting stuck situations
UpdatedComponent->AddWorldOffset(2*MoveOutVector);
}
else
{
......@@ -158,7 +161,7 @@ FVector UVRPawnMovement::GetCollisionSafeVirtualSteeringVec(FVector InputVector,
{
const float SafetyFactor = 3.0f; //so we detect collision a bit earlier
const FVector CapsuleLocation = GetCapsuleLocationFromHead();
const FVector CapsuleLocation = CapsuleColliderComponent->GetComponentLocation();
FVector ProbePosition = SafetyFactor * InputVector.GetSafeNormal() * GetMaxSpeed() * DeltaTime + CapsuleLocation;
const FHitResult TraceResult = CreateCapsuleTrace(CapsuleLocation, ProbePosition);
if (!TraceResult.bBlockingHit)
......@@ -244,11 +247,6 @@ void UVRPawnMovement::ShiftVertically(float Distance, float VerticalAcceleration
}
}
FVector UVRPawnMovement::GetCapsuleLocationFromHead()
{
return HeadComponent->GetComponentLocation() - FVector(0, 0, CapsuleColliderComponent->GetScaledCapsuleHalfHeight());
}
FHitResult UVRPawnMovement::CreateCapsuleTrace(const FVector Start, FVector End, bool DrawDebug) const
{
const EDrawDebugTrace::Type DrawType = DrawDebug ? EDrawDebugTrace::Type::ForDuration : EDrawDebugTrace::Type::None;
......
......@@ -71,8 +71,6 @@ private:
void MoveByGravityOrStepUp(float DeltaSeconds);
void ShiftVertically(float Distance, float VerticalAcceleration, float DeltaSeconds);
FVector GetCapsuleLocationFromHead();
UPROPERTY(VisibleAnywhere) UCapsuleComponent* CapsuleColliderComponent = nullptr;
UPROPERTY() USceneComponent* HeadComponent = nullptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment