This commit is contained in:
Tyrel Souza 2018-02-20 23:57:01 -05:00
parent 5473262240
commit d6dfe7366c
2 changed files with 62 additions and 39 deletions

View File

@ -10,8 +10,7 @@
#define OUT #define OUT
// Sets default values for this component's properties // Sets default values for this component's properties
UGrabber::UGrabber() UGrabber::UGrabber() {
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them. // off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
@ -20,19 +19,58 @@ UGrabber::UGrabber()
// Called when the game starts // Called when the game starts
void UGrabber::BeginPlay() void UGrabber::BeginPlay() {
{
Super::BeginPlay(); Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("Grabber beginPlay"));
///Look for attached physics handle FindPhysicsHandleComponent();
SetUpInputComponent();
}
// Called every fraem
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// if physics handle is attached
// move object holding
// do nothing
}
// Raycast and grab what is in reach
void UGrabber::Grab() {
UE_LOG(LogTemp, Warning, TEXT("GRABBING!"));
// LINE TRACE and Try and reach any actors with physics body collision channel set
GetFirstPhysicsBodyInReach();
// if we hit something attach physics handle
// TODO: attach physics handle
}
// Release
void UGrabber::Release() {
UE_LOG(LogTemp, Warning, TEXT("Released!"));
//TODO: Release physics handle
}
// Look for attached physics handle
void UGrabber::FindPhysicsHandleComponent() {
PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>(); PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
if (PhysicsHandle) { if (PhysicsHandle) {
} else { } else {
UE_LOG(LogTemp, Error, TEXT("%s has no PhysicsHandle"), *(GetOwner()->GetName())); UE_LOG(LogTemp, Error, TEXT("%s has no PhysicsHandle"), *(GetOwner()->GetName()));
} }
}
// Look for attached input component
void UGrabber::SetUpInputComponent() {
InputComponent = GetOwner()->FindComponentByClass<UInputComponent>(); InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
if (InputComponent) { if (InputComponent) {
UE_LOG(LogTemp, Warning, TEXT("%s has a InputHandle"), *(GetOwner()->GetName())); UE_LOG(LogTemp, Warning, TEXT("%s has a InputHandle"), *(GetOwner()->GetName()));
@ -43,23 +81,10 @@ void UGrabber::BeginPlay()
} else { } else {
UE_LOG(LogTemp, Error, TEXT("%s has no InputHandle"), *(GetOwner()->GetName())); UE_LOG(LogTemp, Error, TEXT("%s has no InputHandle"), *(GetOwner()->GetName()));
} }
} }
// Raycast and grab what is in reach FHitResult UGrabber::GetFirstPhysicsBodyInReach() const
void UGrabber::Grab() {
UE_LOG(LogTemp, Warning, TEXT("GRABBING!"));
}
void UGrabber::Release() {
UE_LOG(LogTemp, Warning, TEXT("Released!"));
}
// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
/// Get player View point in this tick /// Get player View point in this tick
FVector PlayerViewpointLocation; FVector PlayerViewpointLocation;
FRotator PlayerViewpointRotation; FRotator PlayerViewpointRotation;
@ -71,17 +96,6 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
FVector LineTraceEnd = PlayerViewpointLocation + PlayerViewpointRotation.Vector() * Reach; FVector LineTraceEnd = PlayerViewpointLocation + PlayerViewpointRotation.Vector() * Reach;
DrawDebugLine(
GetWorld(),
PlayerViewpointLocation,
LineTraceEnd,
FColor(255, 0, 0),
false,
0.f,
0,
5.0f
);
///Setup Query Parameters ///Setup Query Parameters
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner()); FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
@ -96,15 +110,15 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
TraceParameters TraceParameters
); );
/// See what we hit
AActor* ActorHit = Hit.GetActor(); AActor* ActorHit = Hit.GetActor();
if (ActorHit) { if (ActorHit) {
UE_LOG(LogTemp, Warning, TEXT("Line Tract Hit: %s"), *(ActorHit->GetName())); UE_LOG(LogTemp, Warning, TEXT("Line Tract Hit: %s"), *(ActorHit->GetName()));
} }
return Hit;
/// See what we hit
} }
//DrawDebugLine(GetWorld(), PlayerViewpointLocation, LineTraceEnd, FColor(255, 0, 0), false,
// 0.f, 0, 5.0f
//);

View File

@ -9,12 +9,12 @@
#include "Grabber.generated.h" #include "Grabber.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class ROOMESCAPE_API UGrabber : public UActorComponent class ROOMESCAPE_API UGrabber : public UActorComponent
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UGrabber(); UGrabber();
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
@ -28,4 +28,13 @@ private:
UInputComponent* InputComponent = nullptr; UInputComponent* InputComponent = nullptr;
void Grab(); // Raycast and grab what is in reach void Grab(); // Raycast and grab what is in reach
void Release(); // Raycast and grab what is in reach void Release(); // Raycast and grab what is in reach
// Find (assumed) attached physics handle
void FindPhysicsHandleComponent();
// Setup assumed or attached input component
void SetUpInputComponent();
// Return hit for first physics body in reach
FHitResult GetFirstPhysicsBodyInReach() const;
}; };