The issue I am seeing is I have a player pawn which is a car driving down a straight road. I have the car rotate in the z axis (Yaw) when steering left or right. When the player is not steering and the steering wheel is released, I have a function that runs to restore the rotation from its current rotation by lerping:
This has been working perfectly when normally driving. However, my root component is a physics object collider moving through physics and when I collide with another car and the physics naturally add some rotation to the car, the yaw rotation gets stuck and won’t rotate to zero. For example, if after a crash I have rotated 16 degrees in yaw, it won’t go back to 0 degrees it will be stuck at 16. I have tried using Set World Rotation, Add World Rotation, and local/relative versions as well, but this issue keeps happening. Even tried just setting the rotation directly to zero without lerping, as well as a couple other methods but still see the yaw get stuck.
I have assured nothing else in my level is setting or rotating the pawn at this time other than this function and it is not erroring out, the code is running to restore the rotation to zero but it still wont rotate back no matter what I seem to change.
I have checked that use controller rotation is off for all axes since I didnt want to use it for this project. I even tried changing the methodology of this function and the steering completely to rely on the player controller rotation and then enable it and it all works the same and I still get this issue.
Any help or thoughts would be loved for the rest of my life <3.
I might be understanding wrong, but it seems like this blueprint code just resets the rotation that player has changed and not by anything else, right? And you already recognize the root of the problem I think, so the objective should be adding that feature.
Could you try getting the forward vector of your car and comparing it’s direction to the (x = 1, y = 0, z = 0) unit vector? (btw that’s the direction that the engine considers to be 0 degrees) You can achieve this by using the “Dot Product” node, plug both those vectors in and then get the arccos of the result by using the “Acos (deg)” node. If your car’s forward vector also moves, you can simply fix another invisible object on it which’s forward vector faces the same direction with your car’s unmanipulated forward vector. Either way, you will be able to use that direction to turn your car automatically when the player’s not in control and should also work if other factors rotate it! Hope this helps!
I thought by the logic of the code that the world rotation of the object would be taken and lerped to a zero rotation. By my thinking it shouldn’t matter if I rotated the car or if something else rotated it, because I was looking at its world rotation not an amount of rotation that I stored as a variable or anything. So I thought no matter what the world rotation is it should always be moving towards a zero vector rotation, but this doesn’t seem to be working.
I’m not sure how I didn’t think of using the forward vector but that’s a great idea I’ll give that a try thanks!
Oh I think your car only considers one direction to be constantly reset to. Then it should be even easier to achieve this in theory, I also wonder why it doesn’t work. Could you provide where it thinks it should be facing at when a crash occurs? You could try printing out the results. Also, the code you provided doesn’t show when that gets triggered. So could you also clarify that?
Btw just got an idea, could it just be the graphics when you see the car facing at the wrong direction after a crash? And maybe it’s forward vector is indeed facing the road
Yeah,using forward vector dot product method didn’t seem to fix it either.
The car basically has 2 states: Steering and Not Steering.
The steering and not steering functionalities all occur through Tick on the event graph.
The Steering Control and Restore Rotation functions are the last functions run in my tick sequence and run each frame through this branch depending on if we are in the steering state or not:
The results are the same if I hit another car/object if I am in the steering or not steering states.
The car is either steering (lerping between current value and target value; using SetWorldRotation) or not steering (lerping between current value and 0; using SetWorldRotation).
The root component is the physics collider that is being rotated, so the forward vector is rotating. The car mesh is locked rotation and position with no simulated physics, no autoweld, and no collision. When printing to the screen I can see that the root component’s Yaw is what is getting stuck and not the mesh or anything like that.
Thanks for all these additional clarifications! The rotation you’re performing already should affect the root component so it’s behavior after a collision is really intriguing in this case. If we’re not missing anything and these are indeed all the related informations that needs inspection, only certain physics mechanics can explain this situation. Could you try elevating your model from the ground as it is flying, ensuring the root component will be clearly above the ground and then try crashing to see what happens?
Thanks again for your help, but yeah just tried this as well and still same behavior. To begin with I even had the car start a little in air and drop down with gravity to hope to avoid glitching into the road on spawn. But even having it fly any time it collides with something the collider rotates. and the set rotation doesn’t seem to work unless I start steering back and forth then it sometimes snaps back or gets worse. I thought I might be running into a gimbal lock issue but that doesn’t seem to be the case to me.
I’ll have to do some more testing with physics settings or something.
To make sure it has something to do with physics and we’re not missing anything, could you try implementing this exact logic to another actor that doesn’t have the features of your car’s root component?