Improving Godot's ClippedCamera node
Hi, kids! It's been a long time since I've posted anything here.
Anyway, I'm sure you all saw akien's tweet a couple of weeks ago where he released the 3.2 "alpha 0" build. It finally fixed the bug in the ClippedCamera node where it wasn't updating the local z of the camera! Excited, I decided to try it out and posted a video of it properly working.
Now, that's all well and good, and should be good enough for most basic games, right? ... WRONG! And let me tell you why.
The astute viewer will, upon closer inspection, notice several things wrong with the default behavior of the camera.
-- It does not take distance into account. You can move the ClippedCamera 10 units away, or 100 units away, but it will ALWAYS clip straight back to the player, instead of ignoring geometry between it and the player past a certain distance. That's annoying, isn't it?
-- It does not have any smoothing effect whatsoever. Upon clipping, it teleports straight to the player. Upon going back to a non-clipping state, it instantly teleports back. This is disorienting, confusing, and, as one reddit user described it, it feels like a car crash. Not good! A camera should follow the player, not teleport to the player.
-- It is possible to push the camera through geometry (not shown in video). This just shouldn't happen at all.
So, I took it upon myself to attempt to address these issues, and managed to solve them a bit.
It's a bit complicated, but essentially, here's what I'm doing.
--- I have an array that stores three ClippedCamera nodes, one for each "zoom level". They each are parented to a different target than the player. This was necessary to prevent the camera from clipping back to the player at zoom levels greater than 1.
--- I am not using ANY of the ClippedCameras as an actual camera. Instead, I have a master "view camera" that is being fed the information from the currently active ClippedCamera. This way, no matter what zoom level the player is at, it will respond accordingly. I can also use lerp() to smooth out movement! Neat!
--- I am always casting a ray from the view camera back to the player. If it detects a body between it and the player, it will calculate the distance of the camera back to that body. If it is less than the Max Occluding Distance, it will clip through as expected, otherwise, the camera will STAY BEHIND the body.
Here's some videos on the progress so far!
When this is all said and done, I'm locking this up and keeping it for myself and patenting it so I can get rich going to release this on my github page so other people can use it in their games! It's a simple gimbal setup, so you should be able to just drag into your player node and go from there!
I do not have a set release date or schedule or anything. I do have a baby, so my development time is "when I can get to it".
Let me know if there's anything else that you think is missing! And let me know if this is something you would use in your third person games!