Grabbing the object in upright position

I spent several days trying to figure out how to make sure that when I grab and handle the gargoyle, it behaves naturally, but eventually ends up with Z pointing up (upright position), and I couldn’t figure it out. Looks like there is a lot going on behind the scenes in the physics engine and the UPhysicsHandleComponent, so it always gives me weird results no matter what I try besides what is shown in the tutorial.

My latest attempt was to find the shortest geodesic rotation between the component up vector and the world up vector using

FQuat::FindBetweenNormals(HitComponent->GetUpVector(), FVector::UpVector).Rotator();

and then interpolating to it using FQuat:Slerp in tick when setting target location and rotation for the handler, but no luck.

Any idea how to approach this? The behavior that I’m looking for is when I grab and handle the object, it should preserve the angle that I was looking at the object when grabbing it, but naturally rotate it into the upright position. What I want to avoid is fixing the rotation of the object in the world space which leads to unwanted behavior that enables me to “go around” the object and look at it from different sides while holding it.

Not entirely sure what you’re after.

It sounds like you want:

Grab: HitActor->GetActorRotation()
SetTarget: GetComponentRotation()

No, that’s not it. I’ve attached a video.

Grabber

Notice how when I pick it up, it stays on its side. What I want is for it to rotate into an upright position even if I picked it up laying on its side.

Also notice how the gargoyle rotates in front of me as I rotate the camera. The expectation is that I should always see the same side of it (the one that I saw when picking it up) independently of the orientation of the camera in the world.

This is how it should work:

Grabber 2

Except that it should also work exactly like that even if the gargoyle is laying on its side when picking it up.

Does this make sense?

To achieve the behavior on the second video I use FRotator(0., GetComponentRotation().Yaw, 0.); in both Grab and Tick, which essentially uses the Yaw component of GrabberComponent rotator. So I assume I need to somehow tweak the target rotation to align the object Z axis with the world Z axis, but the moment I start messing with it, I start getting weird results.

I’m a little confused by that as that’s what I thought you meant.

So you aren’t after this?
Grabber

Almost. In your example it looks like you’re ignoring the initial rotation of the object. In other words, no matter how (from which side) you pick it up, once grabbed, it will always face right (the gargoyle, I mean). In the video, while on the ground, it clearly faces away from you, so you can see mostly the wings. But when you pick it up, you look at it from its side. This works, but it doesn’t look natural to me.

My intuition tells me that this should be some sort of combination of FQuat::FindBetweenNormals(HitComponent->GetUpVector(), FVector::UpVector).Rotator(); which give you the shortest rotation to orient the z axis up and FRotator(0., GetComponentRotation().Yaw, 0.); to take into account the camera rotation, but all my experiments failed to deliver the result.

I’m not calculating anything, to be clear. This is the result of what I mentioned in my first reply.

With what you’re after it might make more sense to create your own using physics constraints as you would effectively be calculating the target rotation twice; once in your grabber code then again by the physics handle. As what you use in GrabComponent will be used to calculate where to move the component to when using SetTarget. Basically a delta between the two. (The gargoyles face is not pointing forwards).

Privacy & Terms