Can't pick up small objects

I can pick large objects such as a box. But when i’m trying to grab small object(spoon or candle), it just falls. Link to youtube video: https://youtu.be/HwCcrO0r4zk

1 Like

Does it work if you use GrabComponentAtLocationWithRotation?

What should i pass in rotation argument?

The components rotation.

if (!PhysicsHandle) { return; }
HitResult = GetPhysicsBodyInReach();
AActor* ActorHit = HitResult.GetActor();
UPrimitiveComponent* HitComponent = HitResult.GetComponent();

if (ActorHit)
	PhysicsHandle->GrabComponentAtLocationWithRotation(HitComponent, NAME_None, GetLineTraceEnd(), ActorHit->GetActorRotation()); Did I write it correctly?

That should be it. I also forgot that you would need to use SetTargetLocationAndRotation within Tick as well.

I did everything as you said, but the result is the same and now the objects have strange behavior https://youtu.be/M7gfja8iuzE

void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!PhysicsHandle) { return; }

if (PhysicsHandle->GrabbedComponent)
{
	HitResult = GetPhysicsBodyInReach();
	AActor* ActorHit = HitResult.GetActor();
	if (ActorHit)
		PhysicsHandle->SetTargetLocationAndRotation(GetLineTraceEnd(), ActorHit->GetActorRotation());
}

}

if I make object collision much larger, I can take it without any problems.

That might just be the issue then. Could you show your line trace code?

FHitResult UGrabber::GetPhysicsBodyInReach() const
{
FHitResult Hit;
FVector PlayerVPLoc;
FRotator PlayerVPRot;
float Reach = 180.f;

GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerVPLoc, OUT PlayerVPRot);

FVector LineTraceEnd = PlayerVPLoc + PlayerVPRot.Vector() * Reach;

FCollisionQueryParams TraceParams(FName(TEXT("")), false, GetOwner());

GetWorld()->LineTraceSingleByObjectType(
	OUT Hit,
	PlayerVPLoc,
	LineTraceEnd,
	FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
	TraceParams
);

if (Hit.GetActor())
{
	UE_LOG(LogTemp, Warning, TEXT("%s"), *Hit.GetActor()->GetName());
}
return Hit;

}

FVector UGrabber::GetLineTraceEnd() const
{
FVector PlayerVPLoc;
FRotator PlayerVPRot;
float Reach = 180.f;

GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerVPLoc, OUT PlayerVPRot);
FVector LineTraceEnd = PlayerVPLoc + PlayerVPRot.Vector() * Reach;

return LineTraceEnd;

}

And you’re not using complex collision for simple? Do they have a good simple collision?


I created box collision for plate, but it didn’t change much

These don’t look simple enough. What if you made all of them boxes?

It didn’t help

Have you tried adding a debug line? Maybe due to the lack of a crosshair you aren’t hitting where you think you are?

No, I’m hitting the object

Would you mind sending me your project using the following link?

https://gdev.tv/projectupload

Please use File > Package Project > Zip Up Project within Unreal as this will ensure only required files are zipped up and things like the Binaries are excluded.

Privacy & Terms