Skip to content

Instantly share code, notes, and snippets.

@uhusofree
Created January 15, 2021 11:46
Show Gist options
  • Save uhusofree/8f9a6d9c7ce56ace7008d4e456e72973 to your computer and use it in GitHub Desktop.
Save uhusofree/8f9a6d9c7ce56ace7008d4e456e72973 to your computer and use it in GitHub Desktop.
PoK'our hurdling
#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