Is it possible to get the relative rotation of an actor blueprints' component, in degrees?

I’m looking for a way to get the relative rotation in degree values to user/player. This feedback, the rotational degrees, will be used to stop a wheel spinning, said wheel is attached to a vehicle See image below

NOTE: this all runs in real time so we are using event tick. Video link at bottom of post.

[I came across this post, and it works really well if the vehicle never changes it’s Yaw value][1]. This doesn’t work for my application.

I’ve done some digging in regards to the “get relative rotation” node, and the “radians to degree” node, and have not come up with a solution.

My though is that I can set an initial value at event begin play, then compare that over time until the wheel reaches, for example, 45 deg. Right? No luck so far.

Link to video to help explain the problem.

I would like to get the Blue numbers (image below) not the red numbers as feedback.

Found this thread, but not the math behind it.

Simply put, I want deg values from a rotating object.

I’m working out how to mock up what you are saying, but having a bit of trouble doing it. Artist trying to be a programmer here. This is what I have, so far so good yea?

Thanx for your help. OK this is how I’m interpreting what your explaining.

Unfortunately no they are still incorrect. I’ll post a video so you can see what’s happening.

Link

If I understand what you’re trying to fix…pseudocode:

If value is < 0, then get abs(value of rotator)
If value is > 0, then get 360 - value of rotator

abs() is the absolute value node.

Right, if you’re just trying to convert from a rotator to 360 degrees, then that code should work.

Two things, 1) You don’t need the second Branch, as the result of the first branch will reveal whether the rotator is positive or negative…just skip straight into setting the variable. 2) The node to subtract 360 should be reversed…it should be 360 on top, then plug your rotator value into the bottom node so that the resulting equation will be 360 - Rotator Value.

Sure thing, and yep that looks good. Are the values coming out the way you want now?

Ok my fault, we needed to account for the Z axis flipping when you rotate around. This code should work:

OK we got it! I needed to change one node in your code (See red square below) THANK YOU! This should allow me to move on to the next portion of this problem. :slight_smile:

OK, I though we had it. But we are getting closer. I’ll add another reply to the end of the thread with a video link to what is happening now.

Here is the progress we have so far. It’s easier to watch the video than type it all out here.

That said. The issue now is that when the vehicle rotates 180 deg in the world, the feedback also flips. Which means we only get feedback correctly as long as the vehicle doesn’t turn around, this won’t work for my needs. So we will keep trying. :slight_smile:

Thanx again for all the help I can get.

Oof yeah I’m at a loss for that one. You’re correct, since it’s relative, then moving around the world should not impact the values so I’m not sure what’s happening there.

One thought though: I had a lot of trouble working with rotators early on in my game, so I switched and began using vectors instead. The math is a little more involved if you have never worked with vectors before, but it makes calculating relative angles much easier. It’s not an either/or thing…you can use rotators when it makes sense vs vectors and vice versa…it’s just another tool. Dot and Cross Product math would help out here.

Wish I could help more…good luck to you.

No worries, and thanx for all the help so far.

Yea I did find a link (initial post) that does the Dot and Cross Product trick, but it suffers from not being able to rotate in the world and still work.

I feel like we are close, I’ll keep fishing. :slight_smile:

Notes from “Marco (vr_marco)” on discord:

There are few ways I can think of. One is to calculate the angle between the up vector of the body and the up vector of the wheel, assuming at the beginning of the rotation they point in the exact same direction so the relative angle is 0 (zero)

ACosDeg( Dot Product ( Up vector body, up vector wheel ) )
This will give you the angle of rotation of the wheel respect to the body in degrees from 0 to 360

To know the sign you need to calculate another dot product, namely between the up vector of the wheel and the forward vector of the body, then take its sign and multiply it by the the angle out of the Acosd. This should give you the -180 to 180 range.


The other way is to calculate the Delta Rotator and then do an inverse transform rotation using the wheel world transform

So we got this working but, I suspect the discontinuity in the angle is due to the fact that I’m using motors and/or adding torque to your wheels, which causes a slip and makes the angle jump. That would be perfectly normal and may explain what I’m seeing. If not, then I’ll not need to deep dive into the code / setup and see what else it could be.