Free Camera Fly plus Camera Collision

Hi there!

I am new to playcanvas but 3D artist since some decades and know a little about game mechanics in other game engines, but much and nothing about scripting.

I wanted to add a camera to my scene wich is able to fly. This is already working with adding the flyCamera script from the github to the scene camera:

I asked the topics here about “free camera and collision” but got no results for this combination so far. Wondering about that because I thought this feature is often used by viewing 3D objects, e.g. product presentation. Seems I am mistaken about that “often” ^^

So, now this cam should be able to collide with the objects in the scene. The moment you fly, you shouldn’t go through walls. So I also added collision components to all meshes (except “Frame”, it is unimportant right now), switched them to ‘mesh’ and - no camera-collision :frowning:

I guess there has to be some kind of collidable object bound to the camera wich takes care of the collision, right? If so, how to do that? I already have a small box with collision and parente it to the camera and moved also the script to the box. Again, flying is possible, but the box won’t collide with the scene objects.

Has the collision to be added in the script instead? Again, if so, how then?

I already thought this mechanics could be either very easy or very complicated to get to work. It seems to be a bit more complicated, like in other game engines as well (or I always miss the point ^^ ).

Thanks alot for your help in advance :slight_smile:

Hi @KBB and welcome,

Actually it’s not that easy to add collisions to that fly camera script given the way it’s written, or at least without understanding how physics work.

But one quick way to get what you are looking for would be to use this tutorial and example project, first person movement. If you disable gravity in your project settings the player controller will pretty much act like a flying camera moved by forces, and this will respect any colliders it will hit:

Hi Leonidas,
that sounds very good, thanks alot! I’ll have a look in a second.

Thanks, also for answering that fast :slight_smile:

1 Like

Well, okay, that seems to be more than just adding a script to an object ^^

Also, switching gravity to 0 won’t add flying possibility so far, but there is more to do I think: in the example there are parameters visible and changable directly in the editor, my copied script won’t do that (the flyCamera does).

So I’ll have a closer look to the complete scripting tutorial sigh

1 Like