Jump to content

Limiting free camera movement up or down


Recommended Posts


I have applied a freecamera to my project.

camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(-40, cameraHeight,-132), scene);

I have applied gravity to it so that it won't fly

ie: camera.applyGravity = true;

I have given it a constant height (cameraHeight)


scene.registerBeforeRender(function () {
                    scene.activeCamera.position.y = cameraHeight;



Now the problem is that when I move the mouse up and down along the Y axis the camera rotates (in essence on the x-axis). So the camera is elevated and it's like flying.I have checked the ESPILIT demo and it's the same problem (Espilit.babylon has camera gravity enabled).


So is there a command which limits the rotation of the free camera up and down (or left and right) ?

If I need to calculate the rotation in registerBeforeRender then my 2nd question, can I stop a camera?

Link to comment
Share on other sites

  • 2 years later...
  • 4 weeks later...

I use a similar thing to limit the positions of drag drop meshes (called within the onPointerMove) with a limit function

function limit(mesh,xMin,xMax,yMin,yMax,zMin,zMax){

    if (mesh.position.x < xMin){

        mesh.position.x = xMin;


    //Repeat for all arguments


With a little tweaking to refer to the camera and rotations and calling it in the registerBeforeRender, I'm sure you'd be able to limit the camera's rotation to anything you like.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...