Ground movement now works properly for all gravity directions
This commit is contained in:
parent
cf85b7f916
commit
8d8b7fa88c
BIN
GravityStomp/Content/Characters/BP_GSCharacter.uasset
(Stored with Git LFS)
BIN
GravityStomp/Content/Characters/BP_GSCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
@ -45,7 +45,7 @@ void UGSCharacterMovementComponent::PhysFalling(float deltaTime, int32 Iteration
|
|||||||
}
|
}
|
||||||
|
|
||||||
FVector FallAcceleration = GetFallingLateralAcceleration(deltaTime);
|
FVector FallAcceleration = GetFallingLateralAcceleration(deltaTime);
|
||||||
FallAcceleration.Z = 0.f;
|
IsCharacterUpAlignedToWorldUp() ? FallAcceleration.Z = 0.f : FallAcceleration.Y = 0.f;
|
||||||
const bool bHasLimitedAirControl = ShouldLimitAirControl(deltaTime, FallAcceleration);
|
const bool bHasLimitedAirControl = ShouldLimitAirControl(deltaTime, FallAcceleration);
|
||||||
|
|
||||||
float remainingTime = deltaTime;
|
float remainingTime = deltaTime;
|
||||||
@ -359,10 +359,25 @@ void UGSCharacterMovementComponent::PhysFalling(float deltaTime, int32 Iteration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FVector UGSCharacterMovementComponent::GetFallingLateralAcceleration(float DeltaTime)
|
||||||
|
{
|
||||||
|
// No acceleration in Z or Y depending on character up direction
|
||||||
|
FVector FallAcceleration = IsCharacterUpAlignedToWorldUp() ? FVector(Acceleration.X, Acceleration.Y, 0.f) : FVector(Acceleration.X, 0.0f, Acceleration.Z);
|
||||||
|
|
||||||
|
// bound acceleration, falling object has minimal ability to impact acceleration
|
||||||
|
if (!HasAnimRootMotion() && FallAcceleration.SizeSquared() > 0.f)
|
||||||
|
{
|
||||||
|
FallAcceleration = GetAirControl(DeltaTime, AirControl, FallAcceleration);
|
||||||
|
FallAcceleration = FallAcceleration.GetClampedToMaxSize(GetMaxAcceleration());
|
||||||
|
}
|
||||||
|
|
||||||
|
return FallAcceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void UGSCharacterMovementComponent::ComputeFloorDist(const FVector& CapsuleLocation, float LineDistance,
|
void UGSCharacterMovementComponent::ComputeFloorDist(const FVector& CapsuleLocation, float LineDistance,
|
||||||
float SweepDistance, FFindFloorResult& OutFloorResult, float SweepRadius,
|
float SweepDistance, FFindFloorResult& OutFloorResult, float SweepRadius,
|
||||||
const FHitResult* DownwardSweepResult) const
|
const FHitResult* DownwardSweepResult) const
|
||||||
{
|
{
|
||||||
//UE_LOG(LogCharacterMovement, VeryVerbose, TEXT("[Role:%d] ComputeFloorDist: %s at location %s"), (int32)CharacterOwner->GetLocalRole(), *GetNameSafe(CharacterOwner), *CapsuleLocation.ToString());
|
//UE_LOG(LogCharacterMovement, VeryVerbose, TEXT("[Role:%d] ComputeFloorDist: %s at location %s"), (int32)CharacterOwner->GetLocalRole(), *GetNameSafe(CharacterOwner), *CapsuleLocation.ToString());
|
||||||
OutFloorResult.Clear();
|
OutFloorResult.Clear();
|
||||||
@ -650,6 +665,27 @@ void UGSCharacterMovementComponent::SetCharacterUpDirection(FVector NewUpDirecti
|
|||||||
CharacterUpDirection = NewUpDirection;
|
CharacterUpDirection = NewUpDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FVector UGSCharacterMovementComponent::ConstrainInputAcceleration(const FVector& InputAcceleration) const
|
||||||
|
{
|
||||||
|
// walking or falling pawns ignore up/down sliding
|
||||||
|
if(IsCharacterUpAlignedToWorldUp())
|
||||||
|
{
|
||||||
|
if (InputAcceleration.Z != 0.f && (IsMovingOnGround() || IsFalling()))
|
||||||
|
{
|
||||||
|
return FVector(InputAcceleration.X, InputAcceleration.Y, 0.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (InputAcceleration.Y != 0.f && (IsMovingOnGround() || IsFalling()))
|
||||||
|
{
|
||||||
|
return FVector(0.0f, InputAcceleration.Y, InputAcceleration.Z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return InputAcceleration;
|
||||||
|
}
|
||||||
|
|
||||||
void UGSCharacterMovementComponent::OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode)
|
void UGSCharacterMovementComponent::OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode)
|
||||||
{
|
{
|
||||||
if (!HasValidData())
|
if (!HasValidData())
|
||||||
|
@ -24,6 +24,8 @@ public:
|
|||||||
|
|
||||||
// UCharacterMovementComponent interface
|
// UCharacterMovementComponent interface
|
||||||
|
|
||||||
|
virtual FVector ConstrainInputAcceleration(const FVector& InputAcceleration) const override;
|
||||||
|
|
||||||
virtual void OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode) override;
|
virtual void OnMovementModeChanged(EMovementMode PreviousMovementMode, uint8 PreviousCustomMode) override;
|
||||||
|
|
||||||
// walking
|
// walking
|
||||||
@ -42,6 +44,8 @@ public:
|
|||||||
// falling
|
// falling
|
||||||
virtual void PhysFalling(float deltaTime, int32 Iterations) override;
|
virtual void PhysFalling(float deltaTime, int32 Iterations) override;
|
||||||
|
|
||||||
|
virtual FVector GetFallingLateralAcceleration(float DeltaTime) override;
|
||||||
|
|
||||||
virtual void ComputeFloorDist(const FVector& CapsuleLocation, float LineDistance, float SweepDistance, FFindFloorResult& OutFloorResult, float SweepRadius, const FHitResult* DownwardSweepResult) const override;
|
virtual void ComputeFloorDist(const FVector& CapsuleLocation, float LineDistance, float SweepDistance, FFindFloorResult& OutFloorResult, float SweepRadius, const FHitResult* DownwardSweepResult) const override;
|
||||||
|
|
||||||
virtual bool IsValidLandingSpot(const FVector& CapsuleLocation, const FHitResult& Hit) const override;
|
virtual bool IsValidLandingSpot(const FVector& CapsuleLocation, const FHitResult& Hit) const override;
|
||||||
|
Loading…
Reference in New Issue
Block a user