float UCoverComponent::GetDistanceBetweenShapeComponentLocationByVelocityWithDiameter(const FVector2D CoverCharacterShapeComponentLocation, FVector& OutCoverCharacterShapeComponentLocation, const FVector2D CoverCharacterVelocityNormalised, const float CoverCharacterShapeComponentDiameter, const float ShapeComponentHalfHeight, FVector& EndTraceLocation) { OutCoverCharacterShapeComponentLocation = FVector(CoverCharacterShapeComponentLocation.X, CoverCharacterShapeComponentLocation.Y, ShapeComponentHalfHeight); FVector2D EndTrace2D = CoverCharacterShapeComponentLocation + (CoverCharacterVelocityNormalised * CoverCharacterShapeComponentDiameter); EndTraceLocation = FVector(EndTrace2D.X, EndTrace2D.Y, ShapeComponentHalfHeight); return FVector::Dist(OutCoverCharacterShapeComponentLocation, EndTraceLocation); } float UCoverComponent::GetDistanceFromClosestPointOnSplineToEndTraceLocation(const FVector EndTraceLocation, const float CoverCharacterShapeComponentDiameter, const float ShapeComponentHalfHeight, FVector& OutClosestSplinePointToEndTraceLocation) { OutClosestSplinePointToEndTraceLocation = OtherCoverPathSplineComponent->FindLocationClosestToWorldLocation(EndTraceLocation, ESplineCoordinateSpace::World); OutClosestSplinePointToEndTraceLocation = FVector(OutClosestSplinePointToEndTraceLocation.X, OutClosestSplinePointToEndTraceLocation.Y, ShapeComponentHalfHeight); FVector EndTraceFromClosestSplinePoint = OutClosestSplinePointToEndTraceLocation + (FVector(EndTraceLocation - OutClosestSplinePointToEndTraceLocation).GetSafeNormal() * CoverCharacterShapeComponentDiameter); EndTraceFromClosestSplinePoint = FVector(EndTraceFromClosestSplinePoint.X, EndTraceFromClosestSplinePoint.Y, ShapeComponentHalfHeight); return FVector::Dist(EndTraceFromClosestSplinePoint, OutClosestSplinePointToEndTraceLocation); } float UCoverComponent::GetDistanceFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation(const FVector OutClosestSplinePointToEndTraceLocation, const FVector OutCoverCharacterShapeComponentLocation) { return FVector::Dist(OutCoverCharacterShapeComponentLocation, OutClosestSplinePointToEndTraceLocation); } bool UCoverComponent::ConstrainMovementToSplineKeyboardInput(const FVector DirectionBasedOnCameraRotation, const float ActionValue, FVector2D CoverCharacterShapeComponentLocation, FVector2D CoverCharacterVelocityNormalised, const float ShapeComponentDiameter, const float ShapeComponentHalfHeight, FVector& WorldDirection, float& ScaleValue) { FVector OutCoverCharacterShapeComponentLocation; FVector EndTraceLocation; FVector OutClosestSplinePointToEndTraceLocation; float DistanceBetweenShapeComponentLocationByVelocityWithDiameter = GetDistanceBetweenShapeComponentLocationByVelocityWithDiameter(CoverCharacterShapeComponentLocation, OutCoverCharacterShapeComponentLocation, CoverCharacterVelocityNormalised, ShapeComponentDiameter, ShapeComponentHalfHeight, EndTraceLocation); float DistanceFromClosestPointOnSplineToEndTraceLocation = GetDistanceFromClosestPointOnSplineToEndTraceLocation(EndTraceLocation, ShapeComponentDiameter, ShapeComponentHalfHeight, OutClosestSplinePointToEndTraceLocation); float DistanceFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation = GetDistanceFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation(OutClosestSplinePointToEndTraceLocation, OutCoverCharacterShapeComponentLocation); float Hypotenuse = UKismetMathLibrary::Hypotenuse(DistanceBetweenShapeComponentLocationByVelocityWithDiameter, DistanceFromClosestPointOnSplineToEndTraceLocation); FVector DirectionFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation = UKismetMathLibrary::FindLookAtRotation(OutCoverCharacterShapeComponentLocation, OutClosestSplinePointToEndTraceLocation).Vector(); bool bIsCoverCharacterInRangeOfSpline = (DistanceFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation <= Hypotenuse); if (bIsCoverCharacterInRangeOfSpline) { WorldDirection = DirectionBasedOnCameraRotation; ScaleValue = ActionValue; } else { WorldDirection = DirectionFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation; ScaleValue = DistanceFromOutClosestSplinePointToEndTraceLocationToCurrentCoverCharacterLocation - Hypotenuse; } return bIsCoverCharacterInRangeOfSpline; }