IT GRABS!!!
This commit is contained in:
parent
102bf7987e
commit
d7a96d278d
@ -35,7 +35,20 @@ void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompone
|
||||
// if physics handle is attached
|
||||
// move object holding
|
||||
// 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() {
|
||||
UE_LOG(LogTemp, Warning, TEXT("GRABBING!"));
|
||||
// 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
|
||||
// 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() {
|
||||
UE_LOG(LogTemp, Warning, TEXT("Released!"));
|
||||
//TODO: Release physics handle
|
||||
PhysicsHandle->ReleaseComponent();
|
||||
|
||||
}
|
||||
|
||||
// Look for attached physics handle
|
||||
|
@ -37,4 +37,5 @@ private:
|
||||
|
||||
// Return hit for first physics body in reach
|
||||
FHitResult GetFirstPhysicsBodyInReach() const;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user