TPCamera Boom in 3D: Avoiding Obstacles [SOLVED]

Hi, I’m trying to create a proper third-person camera that can move around obstacles such as walls and other objects. Here are my current events:

It works for the most part - the camera avoids walls and moves back to a default distance when no obstacles detected.
CameraBoom

The problem is that the camera is an infinitely small object and this causes it to clip through walls when they are close to it.


I know that in other engines this problem is solved by creating a sphere that does not pass through walls and the camera is placed inside it, which creates this safe distance and prevents the camera from passing through objects. Im not sure on how to make something similar in Gdevelop.

Do you have any ideas on how to avoid camera clipping through the walls? Thank you.

1 Like

CameraBoom2
Solved it. I tried a bunch of ways and found a relatively good one - to use 4 raycasts instead of 1 in a similar way.:


This way the raycast creates a safe radius around the camera and prevents clipping. In addition, it is better to set the “Near Plane Distance” layer parameter to some small value.


The solution is not perfect and im going to try to reduce the number of events + there are minor flaws and sometimes camera still catches a very little pieces of thin/small objects on the very sides, although its very subtle.

I launched Dark Souls 3 out of curiosity, and in the very first random location I found a huge number of places where the camera clips through objects and wall decor elements. Although I completed the game several times, this is the first time I’ve seen it, so apparently those minor flaws are not a problem even during dynamic gameplay and active camera movement.

6 Likes

Thanks for sharing your solution :smiley: . I suspect it’ll become a linked topic soon, once more GDevelop game creators encounter this problem.

I see people trying to make this same stuff.

I tested this in different scenarios - small objects, thin objects, convex and concave surfaces etc. - it works perfectly, no issues, bugs or clipping what so ever so this solution is usable.

One small addition though - subtract a really small value like 1 or 2 from the resulting distance variable so that your camera is actually inside that safe zone described by 4 raycasts.
изображение
And dont set “Near plane distance” to a value less than 1 - it results is visual bugs and Z fighting.

1 Like

Thanks you so much :laughing:

Hey! I don’t suppose you have this as a template or a downloadable project? I’m having trouble with it and would love to sit and look through the events!

1 Like