How Use SetActorRelativeRotation to always keep actor pointing straight up in World Space?

Dear Friends at Epic,

Hi there!

Thanks for UE4!

I am trying to orient a platform that is attached to a rotating skeletal mesh structure.

The platform has had its base set to the socket location of the end of the skeletal mesh structure.

Because the base has been set I am having to use SetActorRelativeRotation in order to change the rotation, as using regular SetActorRotation does not work once the base has been set.


#My Question

What is the best way for me to use SetActorRelativeRotation to cause the actor to always point in a certain direction in world space coordinates?

I have been trying to convert my chosen rotation to local space coordinates and use that,

but now that I think about it, I am not sure that Local space coordinates = Relative Coordinates

Here’s what I have so far

//World Space
FRotator RV_Rot = FRotator(90,0,0);
	
//Get local space of rotator
RV_Vect = TopPlatform->ActorToWorld().InverseTransformVectorNoScale(RV_Rot.Vector());
TopPlatform->SetActorRelativeRotation(RV_Vect.Rotation());

#Converting World Space Direction to Socket Space?

Upon further reflection, I probably am wanting to convert a chosen rotator to the Socket’s local space

or

well im confused between

world space
local space
relative space as per SetActorRelativeRotation

Any ideas how I can achieve my goal as per pics below?

Thanks!


Thanks so much!

Rama

#Update

I got almost the result I want by converting to socket space

Now the issue is that at certain angles of the main skeletal mesh the end platform will jitter sharply.

I am hoping there is an even simpler method than the below, which wont have any jitters :slight_smile:

//converting worldspace rotator to socket space
//to get the desired relative rotation

//

FRotator RV_Rot = FRotator(0,0,0);
	
//Get local space of up dir
FVector RV_Vect = Mesh->GetSocketTransform(Top).InverseTransformVectorNoScale(RV_Rot.Vector());

	TopPlat->SetActorRelativeRotation(RV_Vect.Rotation());

#update

I’ve isolated where the massive jitter is occurring, it is the usual rotator vs quaternion issue

but my problem is I dont know how to get around the jitter using SetActorRelativeRotation, a requirement given that the actor is based

:slight_smile:

The ‘Absolute Rotation’ option on a SceneComponent uses the relative rotation as relative to the world rather than relative to the parent component.

Thanks James!

I also found this just now:

//SceneComponent.h
/** Set the relative rotation of this component to put it at the supplied orientation in world space. */
UFUNCTION(BlueprintCallable, Category="Transform|Component")
void SetWorldRotation(FRotator NewRotation, bool bSweep=false);

Yep that should work too, but you will have to call it every frame, as it is still attached, you are just setting a world rotation at that instant.

Yup, I got it working now, thanks James!