void UGrabber::Grab() { auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); auto ActorHit = HitResult.GetActor(); if (ActorHit) { if (!PhysicsHandle) { return; } PhysicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true); } }
void UGrabber::Grab() { UE_LOG(LogTemp, Warning, TEXT("Grab!!")); FHitResult hitResult = GetFirstPhysicsBodyInReach(); auto ActorHit = hitResult.GetActor(); if (ActorHit != nullptr) { auto ComponentToGrab = hitResult.GetComponent(); //Try and reach any actors with physics body and then attach them physicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true); } }
void UGrabber::Grab() { UE_LOG(LogTemp, Warning, TEXT("Grab pressed!")); auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); auto ActorHit = HitResult.GetActor(); if (!PhysicsHandle) { return; } if (ActorHit) { PhysicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true); } }
void UGrabber::Grab() { /// LINE TRACE and see if we reach any actors with physics body collision channel set auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); // gets the mesh in our case /// If we hit something then attach a physics handle if (HitResult.GetActor()) { PhysicsHandle->GrabComponent( ComponentToGrab, NAME_None, // no bones needed ComponentToGrab->GetOwner()->GetActorLocation(), true // allow rotation ); } }
/// Grabs an object in range void UGrabber::Grab() { /// Try and reach any actors with body collision channel set // LINE TRACE and see if we reach any actors with physics body collision channel set auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); auto ActorHit = HitResult.GetActor(); /// If we hit something then attach a physics handle if (ActorHit) { if (!PhysicsHandle) { return; } PhysicsHandle->GrabComponent( ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true // allow rotation ); } }
void UGrabber::Grab() { /// Line trace and see if we reach any actors whith physics body collision channel set auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); // gets the mesh in our case auto ActorHit = HitResult.GetActor(); // If we hit something then attach a physics handle if (ActorHit) // if ActorHit is not a nullptr { PhysicsHandle->GrabComponent( ComponentToGrab, NAME_None, // No bones needed ComponentToGrab->GetOwner()->GetActorLocation(), true // allow rotation ); } }
void UGrabber::GrabPressed() { ///LINE TRACE and see if we reach any actors with physics body collision channel set auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); //gets the mesh in our case auto ActorHit = HitResult.GetActor(); ///If we hit something, then attach a physics handle if (ActorHit) { if (!PhysicsHandle) { return; } PhysicsHandle->GrabComponent( ComponentToGrab, NAME_None, //No name due to no bone ComponentToGrab->GetOwner()->GetActorLocation(), true //allow rotation ); } }
/// If the physics handle is attached (holding some component) if (PhysicsHandle->GrabbedComponent) // Why is GrabbedComponent variable publicly accessable? { /// Move the object to match pawn's new position FVector LineTraceEnd = GetReachLineEnd(); PhysicsHandle->SetTargetLocation(LineTraceEnd); } } void UGrabber::Grab() { UE_LOG(LogTemp, Warning, TEXT("Grab function called")) auto HitResult = GetFirstPhysicsBodyInReach(); auto ComponentToGrab = HitResult.GetComponent(); // Gets the MESH component of the target actor auto ActorHit = HitResult.GetActor(); if (ActorHit != nullptr) { PhysicsHandle->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true); } } void UGrabber::Release() { UE_LOG(LogTemp, Warning, TEXT("Grab released")) PhysicsHandle->ReleaseComponent(); }