Inner workings question : How does the onCollide function of the camera work?

Let’s say I have a first person camera with an ellipsoid(just like in the documentation) and a simple cube.

Using camera.onCollide = function (colMesh) what actually happens ?

As in the math side of it.

1 Like

It calls an event apparently. Like this (found by digging through playgrounds):

camera.onCollide = function (m) {
   //Do stuff here

I used the camera collisions demo with the onCollide event to move the box:

Touch the box, it moves. (I didn’t know how this worked until now.)


HD, there WAS a time, long ago, when we could “hijack” a camera collider into the playground, and actually watch it work. But since the installation of “webpack” code, I think those days are gone… unless someone knows how.

You can activate lines 16-262, but it just doesn’t work.

Anyway, in the above PG, I am printing camera._collider to console… once per second. You can see that the camera gets no ._collider… until it is translated (positioned). Panning the camera does not set a _collider. Only moving it (arrow keys).

This playground’s original purpose… was to TRY to determine WHY camera->planes collision… was different… depending upon whether you collided with “top” of plane, or “bottom”. Left plane has top facing camera, right plane has bottom facing camera.

The left plane acts correctly, using engine.CollisionsEpsilon properly, and stopping the camera from passing thru the plane.

The right plane… let’s camera pass right thru it.

(Camera cannot enter a building by moving through wall, but CAN exit a building through wall.)

(yawn). Briefly, engine.CollisionsEpsilon sets the amount of collision “angle” needed… for camera to “scrub/slide-along” the collided object… vs. stopping dead. You can play-with that value… and it will affect collisions on the LEFT plane… mainly… what happens if you continue to press up-arrow… after a cam-to-plane collision happens. (whether/not continued camera moves-forward… slide along the surface of the plane, and what angle needed for slide-along.)

SO, I got nothin’. If someone could get the hijacked camera collider to work in playground, then we could watch the collider do it’s stuff… and even make customized colliders for the camera.

If you’d like to see the actual webpack-contaminated JS source for Collider… visit here and then do an in-document search (control-f) for Collisions/collider.ts.

If we could watch it operate… I’d be right next to you, studying the beast. Math-wise, it’s quite an amazing critter, as you can see by its code. Even if someone COULD hand-hold-teach us everything it does, it would likely cause teacher AND students… to go insane. :wink:

But seriously, if anyone knows how to hijack the currently-used collider… into a playground, where we could fill it with console.logs and watch things happen… PLEASE… do it for us. THANKS!

Meantime, I don’t think I have said anything useful for you, here, HD. Sorry.