Problems with rotating follow camera

I am working on a top-down style game with WASD and mouse movement, but I have some problems with getting the camera to rotate correctly.

Trying to make a follow camera that stays behind the player and rotates to the direction the player is facing when moving…

The script below works fine, until you rotate to a certain direction, where something is blocking the camera it looks like…

Here is a video showing the problem at 0:35:

[Youtube link][1]

The camera rotation script

Anyone know why it does this, and how can I fix it?

Thank you…

Hi,

I believe it’s the interpolation that is causing that issue. Working with angles can be a little tricky and may cause such serious issues! The angles in unreal are not represented by full 360 degrees circle (though even that would have caused some issue as 360 degrees == 0 degrees). Let’s take a look at a 360 circle and see how it might be a problem:

Assume you’re increasing the angle toward +360 and your camera is interpolating and trying to reach that value. Now if you increase that value quite fast while your camera angle is still in the upper half circle (i.e. less than 180), if you reach 360, the angle will become 0 and your camera will interpolate backward instead of making a full 360 rotation!

In your case, it’s even more severe and noticeable because unreal represents the angles in the lower half circle with negative values, i.e. ± 180 degrees. So let’s say your camera’s angle is 170 and you’re trying to increase that by another 20 degrees, i.e. interpolating to 190. Instead of a target value of 190 degrees, the Yaw value you use will return -170 and your camera will instead interpolate backward, first to 0 degrees and then toward -170. But as soon as it start to interpolate backward, your target Yaw moves from the 3rd quarter to 2nd quarter (i.e. it changes from -170 (or 190) to let’s say 175. Your camera will then change its interpolation direction which gives you that awful jittering camera.

Can’t you mimic the behavior that you want with a spring arm (you can increase its lag and it might give you a similar behavior). Unfortunately, I haven’t tried to implement such behavior before so I can’t really suggest you a good solution, but here’s a workaround that might work:

Compare the current and target yaw value and see if you’re trying to go from the 3rd quarter to the 4th (i.e. your current is between 90 and 180 and your target is between (-90 and -180). If it is true, then you can add +360 to the target yaw and then pass it to the Target pin of your interpolation node.

Hope this helps and let me know if it worked :slight_smile:

Okay I’ve had some time to look at this again…

I think I understand what you mean, but I have a hard time figure out how I make the script.

Could really use a screenshot or something, showing how I do this.