Help with script - Camera collision

I started using UPBGE 0.3 and the camera collision that worked in blender 2.79 stopped working properly and started flashing in collision. Unfortunately, I’m not very good at scripting. I would like to ask if anyone could create a script that would resolve the camera collision with objects with a certain properity. Or a script that would indicate the distance of the camera from the object in the certain direction and move it accordingly.
Thank you in advance for your help.

  1. Do you get any coding errors in the System Console?

  2. Can you please share a simplified (or large, if you prefer) blend file containing the camera collision logic & scene setup.

Here is a video of what that camera error looks like, while in blender 2.79 it worked flawlessly.
And here is the link to the blender file.

you can take a look at my script here

Thank you, I think you solved my problem.