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?
Thanks!
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.
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!