Here is a project with a quick and easy function that will give you the popular “auto-rotation based on movement” functionality seen in games like dark souls, or many nintendo games such as mario 64 and zelda ocarina of time. It’s efficient, and only requires 3 float variables that can all be adjusted. They are as follows:
-CamRotationFactor: multiplier that controls how much total rotation is added. think of this as the “speed” of your rotation. 1.0 would be the default, adding your exact y input to the yaw each frame.
-CamAngleExponent: exponent that controls how strong or weak “diagonal” input values in-between 0 and 1 are. 0 is default here, which means diagonals would not be affected. Values higher than 1 weaken diagonal influence, while values lower than 0 strengthen it.
-BaseVelocity: what your player’s default “running” speed is, that the function uses in order to scale the rotation speed if you are moving faster or slower in order to keep an “even” amount of rotation for all velocities. this also prevents instant starts/stops, and will prevent the camera from turning while running straight into walls.
Just wanted to say thank you for this, it works amazingly well and is elegant, as maths isn’t my strong point would you mind elaborating on what exactly each part does, for example you find out the power of (ABS of the move direction yaw, camera angle exponent).
Sorry, I thought people could just follow the image, since everything important is right there and pretty simple. I attached a project to the OP post.
that part of the code returns a multiplier to affect the diagonal rotation speed based on the exponent you set. It uses the Abs() because the player Y input might be negative, and we only want the positive value in the calculation. Everything begins to make more sense once you know what the power node does; It’s UE4’s blueprint version of the exponent. For example, if your value is 2 and you put it through the power node with an exponent value of 4, then it is effectively doing this behind the scenes: 2x2x2x2 = 16. Exponents work by multiplying the base number by itself a set number of times.
Now that we know this, if the y input is 1 or -1 (fully right or fully left), nothing will happen because 11 always returns 1 no matter how many times you multiply it. But, if the y input were any amount of diagonal, say, 0.7 (45 degrees), then it will begin to be affected. 0.7^4 would be 0.70.70.70.7 = 0.2401. This is why raising the angle exponent value causes your diagonal rotation to be weaker but not your full left/right.
The second group of nodes takes the length of the player’s current X and Y velocity and divides it by a base value that you set. If your base value is 600, and your velocity is 600, then 1/1 = 1, so nothing about the calculation has changed. But then look at if you had half (300/600 = 0.5) or double (1200/600 = 2), the calculation changes to make the rotation slower or faster.
Finally, we multiply the whole thing by a “total rotation factor”. This is just the same as the “speed” of your rotation. You either add the full value (1.0) or some fraction of it.
Apparently I don’t understand something here. When I think about auto-adjusting camera I think something like camera adjusting itself behind the character. This way we still look at the character from the side view.
Another thing is, in this way when the character moves diagonally, he is basically running in circles. To me it’s pretty weird. Why would I run in circle when I just want to move right?
I’m trying to implement an auto-adjusting camera for my game in these days but I couldn’t get the result I wanted so far. I think it’s because I didn’t fully understand why the character run in circles as a result of these math calculations.
Props to you for making this and sharing with the community though. And maybe you can guide me to the right direction with an answer. I would be glad to hear any advice.