camera.keysUpward not being recognized, plus how to limit freecamera movement up and down

So I have a UniversalCamera, which extends FreeCamera, and I am trying to limit the movement of the camera in the model, which is an office. I want to be able to move above tables and chairs at eye-level height, but also collide with tall furniture, walls, etc without having to set collisionMasks based on model asset naming conventions, nor using moveWithCollision with physical imposters. I currently have a camera that has a collision ellipsoid and gravity turned on so that it stays at eye-level.
First of all, I am trying to switch the camera controls from forward-backward movement depending on the angle of the camera (which is controlled with the mouse) to just having the camera change the orientation, but not have the elevation-movement affected by the camera orientation (e.g. I don’t always want the forward-backward vectors to travel along the z (height) vector when the camera is pointing down or up. I was thinking of restricting this movement by enabling the controls for keysUpward and keysDownward, but I am not sure how to disable this effect of elevation-movement with the mouse. Additionally, for whatever reason, the keysUpwards and keysDownwards properties of the camera are not being recognized. Any thoughts? Thanks!

I think it will help people if you can reproduce in the Playground what you currently have.

That’s the thing. It’s really strange. I FreeCamera.keysDownward is recognized in the playground but not in my app. I can’t really reproduce what I have in the app because most of the code deals with publishing to the website, and the code that isn’t works fine in the playground. I’m wondering if my imports are wrong for accessing FreeCamera variables? But it definitely seems right. It’s just not recognizing this particular variable in keysDownwards. I can access keysDown and keysUp, just not keysDownwards nor keysUpwards.

My imports are below:
import “@babylonjs/core/Debug/debugLayer”;
import “@babylonjs/inspector”;
import “@babylonjs/loaders/glTF”;
import { Engine, Scene, ArcRotateCamera, Vector3, HemisphericLight, Mesh, MeshBuilder, SceneLoader, UniversalCamera, FreeCamera } from “@babylonjs/core”;
import * as BABYLON from “babylonjs”;
import { SceneExplorerComponent } from “@babylonjs/inspector/components/sceneExplorer/sceneExplorerComponent”;

and the compilation error I am getting is:
“Property ‘keysDownward’ does not exist on type ‘FreeCamera’. ts(2339)”
It seems it might be a typescript error, but it’s odd that it’s seemingly only for those 2 variables.

My camera is declared as:
var camera: BABYLON.FreeCamera = new BABYLON.FreeCamera(“Camera”, cameraStartPos, this._scene);

and all of these lines work and compile (except, obviously, for the commented out lines, which are the subject of this discussion):

camera.keysDown = [83, 40];
camera.keysUp = [87, 38];
camera.keysLeft = [65, 37];
camera.keysRight = [68, 39];

//camera.keysUpward = [69];
//camera.keysDownward = [81];

camera.speed = .1;
camera.minZ = 0;
this._scene.gravity = new BABYLON.Vector3(0, -9.81, 0);
camera.applyGravity = true;
camera.ellipsoid = new BABYLON.Vector3(0.05, 0.85, 0.05);
camera.attachControl(this._canvas, true);
camera.collisionMask = 1; //check to see if needed
camera.checkCollisions = true;

were keysDownward and keysUpward deprecated in 4.2.0-beta-13?


keysDownward and keysUpward are new to 4.2 (changes committed on 2020/03/08), I think you have some mismatches somewhere with your packages, your error point to line 2339 whereas there is less than 400 lines in the freeCamera.ts file.

1 Like

Thanks for the response. The TS(2339) is a TypeScript error meaning that Property ‘x’ does not exist on type ‘Y’. Is there a particular verison of TypeScript or related packages/dependencies that babylonjs 4.2.0-beta-13 is not compatible with/requires a minimum version for compatibility?

nevermind, I figured it out. I had created two repos for testing. the one I was running my code in was still 4.1, whereas the new one was 4.2. So I just wasn’t updated to 4.2. Thanks!

1 Like