refactor
This commit is contained in:
parent
5473262240
commit
d6dfe7366c
@ -10,8 +10,7 @@
|
||||
#define OUT
|
||||
|
||||
// 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
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
@ -20,19 +19,58 @@ UGrabber::UGrabber()
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UGrabber::BeginPlay()
|
||||
{
|
||||
void UGrabber::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>();
|
||||
if (PhysicsHandle) {
|
||||
|
||||
} else {
|
||||
UE_LOG(LogTemp, Error, TEXT("%s has no PhysicsHandle"), *(GetOwner()->GetName()));
|
||||
}
|
||||
}
|
||||
|
||||
// Look for attached input component
|
||||
void UGrabber::SetUpInputComponent() {
|
||||
InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
|
||||
if (InputComponent) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("%s has a InputHandle"), *(GetOwner()->GetName()));
|
||||
@ -43,23 +81,10 @@ void UGrabber::BeginPlay()
|
||||
} else {
|
||||
UE_LOG(LogTemp, Error, TEXT("%s has no InputHandle"), *(GetOwner()->GetName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Raycast and grab what is in reach
|
||||
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)
|
||||
FHitResult UGrabber::GetFirstPhysicsBodyInReach() const
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
/// Get player View point in this tick
|
||||
FVector PlayerViewpointLocation;
|
||||
FRotator PlayerViewpointRotation;
|
||||
@ -71,17 +96,6 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
|
||||
|
||||
FVector LineTraceEnd = PlayerViewpointLocation + PlayerViewpointRotation.Vector() * Reach;
|
||||
|
||||
DrawDebugLine(
|
||||
GetWorld(),
|
||||
PlayerViewpointLocation,
|
||||
LineTraceEnd,
|
||||
FColor(255, 0, 0),
|
||||
false,
|
||||
0.f,
|
||||
0,
|
||||
5.0f
|
||||
);
|
||||
|
||||
///Setup Query Parameters
|
||||
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
|
||||
|
||||
@ -96,15 +110,15 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
|
||||
TraceParameters
|
||||
);
|
||||
|
||||
/// See what we hit
|
||||
AActor* ActorHit = Hit.GetActor();
|
||||
if (ActorHit) {
|
||||
UE_LOG(LogTemp, Warning, TEXT("Line Tract Hit: %s"), *(ActorHit->GetName()));
|
||||
}
|
||||
|
||||
/// See what we hit
|
||||
|
||||
|
||||
|
||||
|
||||
return Hit;
|
||||
}
|
||||
|
||||
|
||||
//DrawDebugLine(GetWorld(), PlayerViewpointLocation, LineTraceEnd, FColor(255, 0, 0), false,
|
||||
// 0.f, 0, 5.0f
|
||||
//);
|
@ -9,7 +9,7 @@
|
||||
#include "Grabber.generated.h"
|
||||
|
||||
|
||||
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
||||
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
|
||||
class ROOMESCAPE_API UGrabber : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
@ -28,4 +28,13 @@ private:
|
||||
UInputComponent* InputComponent = nullptr;
|
||||
void Grab(); // 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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user