Quality of Life fix for Grabber.cpp in Building Escape Game

I kinda hated how the objects would handle when you would pick them up and try and manipulate them. I’d end up dragging them on the ground because gravity would constantly be pulling the object away from the grabber and they’d be spinning in dumb ways making it hard to place. So I adjusted the code so that you grab the object with rotation and disable the gravity then enable gravity when released.

void UGrabber::Grab()

{

LookForObject();

FHitResult HitResult = GetFirstPhysicsBodyInReach();

UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent();

if(HitResult.GetActor())

{

    PhysicsHandle->GrabComponentAtLocationWithRotation(

        ComponentToGrab,

        NAME_None,

        LineTraceEnd,

        PlayerViewRotation

        );

    UPrimitiveComponent* GrabbedComponent = PhysicsHandle->GetGrabbedComponent();

    GrabbedComponent->SetEnableGravity(false);

}

}

void UGrabber::Release()

{

UPrimitiveComponent* GrabbedComponent = PhysicsHandle->GetGrabbedComponent();

if(!GrabbedComponent) {return;}

else

{

GrabbedComponent->SetEnableGravity(true);

PhysicsHandle->ReleaseComponent();

}

}

Actually, proud of this fix. Works beautifully.

  • LMNTreePenguin
1 Like

Privacy & Terms