What I mean is: when the character is running forwards, if the player pushes the joystick backwards, the character does an instant 180 turn and starts running the opposite direction. Increasing the rotation rate is not what I want because I want to use a transition animation. Similarly, I want an instant 180 turn when the character is standing still and taps the movement input (joystick or keyboard WASD) in the opposite direction.
It is a common practice in many videogames but I’m unable to code it. Does anybody know how to approach this? I can make a custom event that does the 180 on the press of a button but I want to integrate it on the moveinput event like most games do.
Let’s start from the basics.
First of all, you need to compare the angle between the camera and movement direction
At the second, you need to change rotation speed accordingly to this angle, bigger angle = larger rotation speed.
Also, to make it smooth - use the RInterp node each tick
First to make it all secure and correctly oriented for player character game multiply all those vectors by [1,1,0] vector (ie. remove Z axis component)
Then NORMALIZE all of them.
Now DOT product between forward vector and camera vector is cosine of triangle made by them. So arcus cosine will give you angle in degrees
And here is what you need that RIGHT vector for: DOT product will give you angle between right and forward of camera. It will also give you sign for that angle calculated from forward vector.
So your direction in degrees is:
acos(DOT of forward vector and camera vector) * sign(acos(DOT of right vector and camera vector))
ps.
dont forget about multiply by [1,1,0] and NORMALIZE.