IT GRABS!!!

This commit is contained in:
Tyrel Souza 2018-02-22 21:31:40 -05:00
parent 102bf7987e
commit d7a96d278d
2 changed files with 28 additions and 1 deletions

View File

@ -35,7 +35,20 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
// if physics handle is attached // if physics handle is attached
// move object holding // move object holding
// do nothing // do nothing
/// Get player View point in this tick
FVector PlayerViewpointLocation;
FRotator PlayerViewpointRotation;
GetWorld()->GetFirstPlayerController(
)->GetPlayerViewPoint(
OUT PlayerViewpointLocation,
OUT PlayerViewpointRotation
);
FVector LineTraceEnd = PlayerViewpointLocation + PlayerViewpointRotation.Vector() * Reach;
if (PhysicsHandle->GrabbedComponent) {
PhysicsHandle->SetTargetLocation(LineTraceEnd);
}
@ -47,9 +60,20 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
void UGrabber::Grab() { void UGrabber::Grab() {
UE_LOG(LogTemp, Warning, TEXT("GRABBING!")); UE_LOG(LogTemp, Warning, TEXT("GRABBING!"));
// LINE TRACE and Try and reach any actors with physics body collision channel set // LINE TRACE and Try and reach any actors with physics body collision channel set
GetFirstPhysicsBodyInReach(); auto HitResult = GetFirstPhysicsBodyInReach();
auto ComponentToGrab = HitResult.GetComponent();
auto ActorHit = HitResult.GetActor();
// if we hit something attach physics handle // if we hit something attach physics handle
// TODO: attach physics handle // TODO: attach physics handle
if (ActorHit) {
PhysicsHandle->GrabComponent(
ComponentToGrab,
NAME_None,
ComponentToGrab->GetOwner()->GetActorLocation(),
true //allow rotation
);
}
} }
@ -57,6 +81,8 @@ void UGrabber::Grab() {
void UGrabber::Release() { void UGrabber::Release() {
UE_LOG(LogTemp, Warning, TEXT("Released!")); UE_LOG(LogTemp, Warning, TEXT("Released!"));
//TODO: Release physics handle //TODO: Release physics handle
PhysicsHandle->ReleaseComponent();
} }
// Look for attached physics handle // Look for attached physics handle

View File

@ -37,4 +37,5 @@ private:
// Return hit for first physics body in reach // Return hit for first physics body in reach
FHitResult GetFirstPhysicsBodyInReach() const; FHitResult GetFirstPhysicsBodyInReach() const;
}; };