Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to throw a grabbed component with physics handle?

I managed to grab a component using a physics handle and GrabComponent(), I want to be able to throw my object, I can "throw" it by moving the camera right and left and release the mouse button, but I'd like to be able to right click and form a trajectory with the component with c++, how can I achieve this ?

Thanks for helping.

Product Version: UE 4.13
more ▼

asked Dec 12 '16 at 11:59 PM in C++ Programming

avatar image

6 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi, Drakota.

I was facing the same problem, and I had solved it using UPrimitiveComponent::AddImpulse() function. Here's how I did it:

First, I made sure that I was saving the HitResult globally when line-tracing (ray-casting) on an object to grab. Then I retrieved the component being grabbed from the HitResult and applied an impulse on it.

 void UGrabber::Throw()
     auto ComponentGrabbed = HitResult.GetComponent();
     int rate = 1000; /// Rate at which the impulse is applied.

     /// Checking if the object is first grabbed before throwing.
     if (HitResult.GetActor() && bIsObjectGrabbed)
         /// (Using player's forward vector to determine direction of throw).
             GetWorld()->GetFirstPlayerController()->GetActorForwardVector() * rate,
             NAME_None, /// No bone names for specific  objects.
             true /// Makes sure that mass is immaterial to the force.
         bIsObjectGrabbed = false;

In the above gist, bIsObjectGrabbed is a global Boolean which is set to true when the object is grabbed, and set to false when the object is released or thrown.

For some reason, if you hadn't used line-trace to get the HitResult, where how to achieve it:

 void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
     FVector PlayerViewPointLocation;
     FRotator PlayViewPointRotation;

     FVector LineTraceEnd = PlayerViewPointLocation + (PlayViewPointRotation.Vector() * Reach);
     /// Performing Line-Tracing (Ray Casting).
     FHitResult Hit;
     FCollisionQueryParams TraceParams(FName(TEXT("")), false, GetOwner());
     /// Saving the output hit result for the grabber mechanism.
     HitResult = Hit;
     if (Hit.GetActor() != NULL)
         UE_LOG(LogTemp, Log, TEXT("Line trace on: %s"), *Hit.GetActor()->GetName());
     /// Setting Component's grabbed location to Ray-Cast end.
     if (PhysicsHandle->GrabbedComponent)

more ▼

answered Feb 03 '18 at 07:09 PM

avatar image

Brave Bone
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question