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.
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?
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.
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.
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.
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.
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.
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.