Local rotation of component

Hi,

I’m new to Unreal, I use C++, not scripting. I have a model of armored vehicle with several moving parts: Body, turret and gun barrel on turret.
I exported model from Blender as FBX file, imported it into Unreal. In C++ application, I created class derived from Actor and
objects of USkeletalMeshComponent class for parts, and load proper meshes: vehicle body (attached to root component),
turret (attached to body) and barrel (attached to turret).

I would like to change turret azimuth. I understand that SetRelativeRotation sets rotation of component in axis of its parent
component, but I would like to rotate component locally.
Is AddLocalRotation supposed to do it ? When I use it, it seems to rotate turret around axis of parent component (vehicle body)
not its own. It seems to behave the same way as SetRelativeRotation.
Do I miss something obvious ?

Another problem - is there any way to retrieve current local rotation ? I don’t see GetLocalRotation method.

Thanks in advance for any help.

Best regards,

2 Likes

From analogy of BP, AddLocalRotation is different to SetLocalRotation in a way how going over 0 and 180 degrees is treated. When new rotation is over the limit it will “normalize” values for you. You could always get LocalRotation from components transform, if function is missing.

Thanks, but it does not really help. I set angle in -180…+180 degrees range and component seems to rotate around its parent axis, not around its own. Do you have any idea what may be wrong ?

Regards,

I’ve re-read your first post and honestly I have no idea what you mean by rotate object locally not in the axis of the parent. Both SetRelativeRotation and AddLocalRotation change transform of the component, then component transform is multiplied by the transform of the parent/socket to which its attached. So if you rotate your actor by 30 degrees pitch and then rotate component by 45 degrees yaw then you will have a combined rotation.
Do you want to rotate turret into a specific direction regardless of what is the rotation of the parent?

By rotating object locally I mean rotating in its own axis, not parent axis. Turret is located on vehicle body, but turret center is about 1 meter behind body center, so there is 1 m distance between body and turret Z axes.
When I do

turret->AddLocalRotation(FRotator(0.0, delta, 0.0));

turret rotates by angle requested, but apparently in body Z axis (too close to barrel), not its own.
I hope it more clear now.

1 Like