I have a physics object (actor) thats being rotated to the angle of the floor below it using a line trace - so it always stays upright on a surface. Then I add forces to make it slide over the floor. This works well but now I’m trying to rotate the object and change its linear velocity accordingly which is giving me issues.
Basically it has to behave like a car: when you turn right or left, the linear velocity follows the new direction you’re facing.
So I rotate the object in place using SetActorRotation, then I rotate the linear velocity with corresponding values. I actually got this to work but it’s a bit of a hack and only works properly on a flat plane. As soon as my object is tilted because of a slope and I rotate my object, the linear velocity thats being rotated is pushing the object into the air.
When the player presses left or right, it executes this code to rotate the linear velocity accordingly.
This doesn’t work as intended in 3D space since it’s hardcoded to rotate the Z axis. It does exactly what it should when the object is on a flat plane though.
link: video example of unintended behaviour
If you watch the video, you can see what happens when rotating on a slope with sufficient speed. When it drifts into the air I actually want it to “stick” to the surface.
I tried making a rotator using the actor’s forward vector together with RotateVector but I always get odd and unintended results, mainly because I don’t really know how to do this. How am I supposed to get the proper axis and/or rotate the linear velocity to match the new direction the actor is facing?