Check Collision after camera position changed

i change the camera position

  1. have i any event for know about collision camera with other object ?
  2. how can correct the movement like automatic camera movement when i manually change camera position by code?

One idea:

If you parent an object to the camera…like a cube as an example, then you can use collision with the cube. So the cube would move when the camera moves and you can use that for collision detection.

1 Like

hey thanks that is good idea but let me show you what is the main problem in PG

i need camera move same as when we walk move with keys [up- left -down back]

Forgive me as I’m having a difficult time understanding exactly what you’re trying to do. It sounds to me like you’re interested in getting standard FPS-like controls for your camera?

You’re actually already using the free camera which has these built in for you…so in the playground you posted, I can use the arrow keys to move the camera around as you describe.

Again please forgive me if I’m misunderstanding.

dear @PirateJC it is for my bad english too :slight_smile:

i really need know about that
the main question is where i can update camera (by check collision) after transform manually?

Have you tried camera.onAfterCheckInputsObservable?

Also, you have onViewMatrixChangedObservable and onProjectionMatrixChangedObservable.

1 Like

i will read about them thanks i let you know if i cant get

hi again
i think i explain that wrong
look this example
i want when camera moved automatically (not buy input) and hit the box that not go inside the box


I probably misunderstand what you’re looking for because the @PirateJC’s solution looks good to me. Here is a basic example with a box attached to the camera and used to check for collision when the camera move automatically:

please excuse me if my answer is out of scope :grimacing:

hi thanks
i dont wanna stop when camera hit the box i wanna that movement path corrected after camera hit any mesh

Hi, thank you for the precision.
You can probably take a look at the navigation mesh extension:

As a quick example, I’ve just reuse an existing PG ( founded here Babylon.js Documentation) and add your camPlay() function: