PhysicsHandle->GrabComponent(
ComponentToGrab, //ComponentToGrab
NAME_None, //grab what bone name, if any
ComponentToGrab->GetOwner()->GetActorLocation(), //grab location
true //allow rotation
);
When you compile this code in Unreal 4.18, you’ll get this warning since this GrabComponent seems to be deprecated
warning C4996: 'UPhysicsHandleComponent::GrabComponent': Please use GrabComponentAtLocation or GrabComponentAtLocationWithRotation Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile
Instead of using GrabComponent, you can use GrabComponentAtLocation or GrabComponentAtLocationWithRotation instead
PhysicsHandle->GrabComponentAtLocation(
ComponentToGrab, //ComponentToGrab
NAME_None, //grab what bone name, if any
ComponentToGrab->GetOwner()->GetActorLocation() //grab location
);
With this code, as you fly around holding the object, the object will dangle wildly from the point at which it’s being held, like it’s being tossed about in a hurricane. This is because the object is being held at a single point and the rotation is being handled by the physics engine.
PhysicsHandle->GrabComponentAtLocationWithRotation(
ComponentToGrab, //ComponentToGrab
NAME_None, //grab what bone name, if any
ComponentToGrab->GetOwner()->GetActorLocation(), //grab location
ComponentToGrab->GetOwner()->GetActorRotation() //grab rotation
);
With this updated code, as you fly around holding the object, the object will always point in the same direction (rotating in your hands, to maintain the the held object’s same rotation) as your point of view changes. This is because the rotation is no longer being calculated on the fly. Instead rotation is being passed as a parameter to the method.