Rotating actor relative to camera position

Hello,

Im puzzling my mind on rather simple task. Rotating actor relative to camera position (camera space). I feel like I know the basics and how it should work, but it just doesnt. Rotators are very confusing.
I wish I could just provide axis to rotate around.

Please check out my sample project or screenshot below. I want to rotate this cube in screen space. No matter from which direction I look at it, it will rotate along camera’s x axis located in the middle of cube. Hope it make sense.

Thanks!

https://drive.google.com/file/d/0B7TF3ey_iydnUW9UU3NaZGdabG8/view?usp=sharing

2faefd84ac4164368966d99305dba77063edd6df.jpeg

f8de10ce3b4bafae62dd02fc8d51240f7190aea6.jpeg

You can get forward, right and up vector of the camera. Then you can rotate vector around axis, for eg. forward vector of cube rotate around up vector of camera. Result will be some vector that is length 1. Then you can find rotation by applying this to find look at rotation, from [0,0,0] to your rotated vector value.

You can also find that rotation with other nodes, but i think find look at rotation will be best here. Watch for near pole artifacts.

Nawrot, thanks for reply. Unfortunately, I couldnt get it working. I dont get how rotators work. Its a roll, pitch, yaw, but in a local space of rotated object right ? Then how can I convert world space axes to local space rotator. When I create MakeRotationFromAxes with [1,0,0][0,1,0][0,0,1] values, then object wont rotate at all(just for test).

Again, here is what Im after.

This setup gave me cube rotating in many directions, nothing consistent.

here is solution:

605c654aefed745d9d573277c3de4b7e24b316b0.jpeg

This whole vector math on last picture is bogus.
First you are getting vector from cube to camera.
Then you zero X and Y, leaving only Z.
Rotator from axis and Angle normalizes that vector.
So if you plugged only [0,0,1] into rotator from axis you would have same result.

The node with big X before RotatorFromAxisAndAngle is a cross product, not multiplication.


voidAInspectable::ArbitraryAxisRotation(const FVector& POVForwardAxis, const FRotator& InputRotation)
{
	const FQuat POVQuat = POVForwardAxis.ToOrientationQuat();

	const FQuat RollQuat(POVQuat.GetForwardVector(), InputRotation.Roll); // X Axis
	const FQuat YawQuat(POVQuat.GetUpVector(), InputRotation.Yaw); // Y Axis
	const FQuat PitchQuat(POVQuat.GetRightVector(), InputRotation.Pitch); // Z Axis

	const FQuat DeltaQuatToApply = PitchQuat * (YawQuat * RollQuat);
	this->SetActorRotation(DeltaQuatToApply * this->GetActorQuat());
}

if anyone is still interested in a solution
Thanks at [MENTION=3798]Sion Sheevok[/MENTION] (Discord) who helped me with this.

1 Like

Can someone translate this to blueprint please?