Dynamic Grabber distance for target location

With using the Grabber Reach value to set the target location distance I was finding whatever was being grabbed might pop to that value, sometimes causing some bananas physics.

I’ve added another float member variable GrabDistance in the header which whenever Grab() is called gets its value set using the value from HitResult.Distance -

GrabDistance = HitResult.Distance;
PhysicsHandle->GrabComponentAtLocation(ComponentToGrab,	NAME_None, PlayerViewPointLocation + PlayerViewPointRotation.Vector() * GrabDistance);

Then down in TickComponent it’s used to set the target location -

PhysicsHandle->SetTargetLocation(PlayerViewPointLocation + PlayerViewPointRotation.Vector() * GrabDistance);

Having game play move out/in functionality on the grabber was useful too, so I bound the mousewheel scrolling to the 2 functions below which either adds or subtracts a float value GrabDistanceStep to GrabDistance. -

void UGrabber::MoveGrabOut()
{
	GrabDistance = FMath::Min(GrabDistance + GrabDistanceStep, ReachMax);
}

void UGrabber::MoveGrabIn()
{
	GrabDistance = FMath::Max(GrabDistance - GrabDistanceStep, ReachMin);
}

Not a huge amount of extra code, but seemed like a nice addition to game play :slight_smile:

1 Like

Awesome job going the extra mile!