Created
January 15, 2021 11:46
-
-
Save uhusofree/8f9a6d9c7ce56ace7008d4e456e72973 to your computer and use it in GitHub Desktop.
PoK'our hurdling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HurdleComponent.h" | |
#include "PlayerCharacter.h" | |
#include <Components/ActorComponent.h> | |
#include <Components/SceneComponent.h> | |
#include <GameFramework/Actor.h> | |
#include <DrawDebugHelpers.h> | |
#include <CollisionQueryParams.h> | |
UHurdleComponent::UHurdleComponent() | |
{ | |
HurdleStrength = 400.f; | |
HurdlePitchAngle = 25.f; | |
} | |
void UHurdleComponent::SetPlayer(APlayerCharacter* Character) | |
{ | |
Player = Character; | |
} | |
void UHurdleComponent::TakeAction() | |
{ | |
if (Player) | |
{ | |
FVector HurdleVelocity = GetHurdleVelocity(); | |
Player->LaunchCharacter(HurdleVelocity, true, true); | |
} | |
} | |
FVector UHurdleComponent::GetHurdleVelocity() | |
{ | |
FRotator HurdleDirection = Player->GetActorRotation(); | |
HurdleDirection.Pitch += HurdlePitchAngle; | |
return HurdleDirection.Vector() * HurdleStrength; | |
} | |
FVector UHurdleComponent::FindEdgeHurdleLocation(FVector HurdleStart, bool& HurdleHit, FHitResult& HurdleHitResult) | |
{ | |
FVector Direction = FVector::DownVector * 100; | |
FVector StartTrace = GetStartTraceVector(HurdleStart, HurdleHitResult.ImpactPoint); | |
FVector EndTrace = StartTrace + Direction; | |
FCollisionQueryParams TraceParams(FName(TEXT("hurdle")), true, Player); | |
FHitResult Hit(ForceInit); | |
Player->GetWorld()->LineTraceSingleByChannel(Hit, StartTrace, EndTrace, ECollisionChannel::ECC_Pawn, TraceParams); | |
return Hit.ImpactPoint; | |
} | |
FVector UHurdleComponent::GetStartTraceVector(FVector HurdleStart, FVector ImpactPoint) | |
{ | |
float X, Y, Z; | |
Z = HurdleStart.Z; | |
X = ImpactPoint.X; | |
Y = ImpactPoint.Y; | |
return Player->GetActorForwardVector() + FVector(X, Y, Z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment