Calculate a Roll Rotation to Face Center of a Circle

Hi, I spawn a couple of rectangular boxes on the outer perimeter of an (imaginary) circle. So all boxes are positioned at a radius of, say 100.

I got the position figured out but now I want to calculate a roll for all boxes, so their up vectors all point towards the center of the circle (the circle’s forward vector is the x-axis direction, btw.).

How do I calculate the rotation for all those boxes (using blueprints)? My vector maths are a little rusty so please excuse me if this is a simple question to solve.

Thank you in advance for your help

There’s a node, ‘look at rotation’. You can use that :slight_smile:

1 Like

That node sadly does not seem to do the trick because it just calculates any kind of rotation, i.e. it does not keep pitch and yaw at zero und only rotate around the roll axis. I need a way to only calculate the correct roll to look at the center.

By default, it will change all axes to suit the rotation. But you can limit which ones it uses. It is what you need :slight_smile:

For example ( your example ), keep the X and Y, but only set the Z with this node…

1 Like

Okay, I guess I just misunderstood you. I thought you were talking about the “Find Look At Rotation” node. That’s the one I tried previously and I does not have a way of restricting axis. However, I guess you meant the “Look At Function” which produces a whole transform but let’s you define exactly what kind of look at you need, like you said.
So this is how I used it in the end to achieve what I wanted to do:

Screenshot 2024-07-21 205743

Thanks for your help!

1 Like

For your future reference:

Also, make sure to give ClockWork credit for answering your question.

Good luck!

1 Like

lIf I’m not mistaken Look at rotation assumes up is (0.0, 0.0, 1.0) and only calculates for yaw and pitch.

1 Like

I think it’s independent :sweat_smile:

LookAt is designed to avoid rolling.

If you specifically want to to use roll to point the up vector towards target, you can use this.
In that graph, “Self” is my circle actor and its location is the center.

It also assumes that the boxes are already spawned with the same rotation as the circle. If that’s not the case, call SetActorRotation(Circle->GetRotation) before adding the local roll offset.

Here’s the first part so you can see it :

image

2 Likes