Jump to content

I need a bit help with the camera inputmanager to define keyboard inputs


Recommended Posts


I've just started with BJS shortly (like many others before me ... ;) ).

At the first - yes i have read alot in documentations, samples, in this forum because i wanted to know, if its possible to do, what i want to do/try with BJS :)

- The target, what i want to reach at first is: I want to "fly" around the "space" with my own keyboard controls/keys.

The problem where i hang on at this moment is , i have to less knowledge of the possible base-functions and names of it, and how to use ist. I have a simple 3D scene, in it i tested serval cameras and other stuff, but didnt find the "one" cam, who already have all abilitys for a "6-DOF" movement. (6-DOF = "Six Degrees Of Freedom", means absolutly free movement, pitching, rolling, spinning, moving, sliding -unlimited.)
... but i think, the cam's can do it, it "simply" have to be defined by myself. (like modding the fly-cam or the free-cam, adding conrols, ... .)

Q: What would be the most matching / usable cam for a 6-DOF-movement?

The next is, i looked alot in documentation - like how to define controls ( http://doc.babylonjs.com/how_to/customizing_camera_inputs )- there are samples with "addGamepad()". There are other predefined things available like "addKeys" or "addKeyboard" ,  for keyboard inputs?

- Is anywhere a list of base-deinitions for cam-movements, for banking/rolling, pitching, steering and so on, with samples ?

Okay, thats alot questions for the first time ... but i have even more about it in my head ;).

Link to comment
Share on other sites

Hello and welcome!

Q1: Probably the FreeCamera because you can control its rotation using rotationQuaternion property

Q2: Yes: addKeyboard() (http://doc.babylonjs.com/api/classes/babylon.freecamerainputsmanager)

Q3:  camera.rotationQuaternion will let you control the rotation with a quaternion. If you are not familiar you can use camera.setTarget() to control banking and pitching. Roll can be controlled by settting camera.upVector

Link to comment
Share on other sites


I have anywhere a error/mistake or there is anything i dont know and/or didnt find out.
X and Y rotations are working, but the "Z" rotation i dont get to work. (Banking/Rolling)
 ... anyone have a idea, what i missed ?

... edit: moved to playground ...

Edited by Wormaus
code moved to playground
Link to comment
Share on other sites

20 hours ago, Wormaus said:

Notice: you have to click into renderwindow with mouse to get it working. (Why i dont really know, but i think its because i removed mouse controls from cam in the script ... )

Because the renderwindow has to have focus for keys to work. (same for mouse but as you click before moving an object focus is set)

cameraRotation is a Vector2 so no .z  use rotation or rotationQuaternion



Link to comment
Share on other sites

So its much more complicated then i was thinking. (All 3D tools/programs i used to this time had for the cam/viewpoint an "x", "y" and "z" rotation. In my mind it was a logic to have "xyz" - position - rotation - movement - values as basics.)

I serached a while for it here and at playgound, but didnt find any sample. (I know, they must be here or there, so i'm possible blind ...)

Link to comment
Share on other sites

3 minutes ago, Wormaus said:

All 3D tools/programs i used to this time had for the cam/viewpoint an "x", "y" and "z" rotation. In my mind it was a logic to have "xyz" - position - rotation - movement - values as basics.

???? It does! what is wrong with .rotation, .rotationQuaternion??

Link to comment
Share on other sites

[joke on] ... hmm, da müsste ich jetzt hier mit mantissen und dekadische logarhitmen oder Stöchiometrie und co anfangen ... , wäre wohl vergleichsweise ähnlich schwer sich da durchzuarbeiten. Das hatte ich wenigstens noch in den anfang 80-ern in der Schule. ^^ ;)  ... [joke off]

Das mit der "Quaternion" hab ich jetzt in Bezug zur "Z"-rotation der Kamera / des Viewpoints aber immer noch nicht verstanden.




Link to comment
Share on other sites

Okay, the wiki link wans not the best solution for me, its describes this in a very complicated way. (It looks usable for anyone who already know waht it is, but nor for people who never had to do anything with it.)
The better link for me was the babylon docs, found it via google. https://doc.babylonjs.com/api/classes/babylon.quaternion

Now i know what it is/mean (quaternion) releated to babylonjs, but not how to work with it.

There are really no "6DOF" Cam prepared with the feature
  - simply add movement-controls and use it (Rotation in 3 axis, moving in 3 axis)
  - let movement of the cam (or object, where the cam will be fixed attatched) be releated to origin as "self" OR the "world"

To create a cam like this it looks for me so complicated that i think, i'll never will get it ready. But it's one of the basic things i need, to realize this things i wanted do.

Link to comment
Share on other sites

Hi JohnK.

All in all you're right, it is like a fly-cam or "freespace"-cam. (but without any angle/rotation- limitations and without any autobalancing)

I try'ed out some things with the different cams and i was playing with it a bit, so i learned a bit more about the cams and behaviours. But not enough to create this, what i want have. Therefor i have to learn even more.
I have seen there are alot more things behind it i have to look at / to know , then i thought before.

The next ist, i will look at the flycam again, now with a bit more learned things.
( So i remember, the problem i had with flycam, there was pich and yaw- controls, but no roll- controlls. But just the direct roll control i need too. I'll check it out again for me, may be i knew to less last time, when i was trying this cam.))

Link to comment
Share on other sites

5 hours ago, dddougal said:

I think the problem is actually that he doesn't know what a quaternion is.....I think this explains it quite well : https://doc.babylonjs.com/resources/rotation_conventions


Yes, you're right. I didnt know the "quaternion" and "euler", because all tools i used over the last 25 years had a "simple" "alpha/beta/gamma" and "XYZ" -assigned action like TurnBy(axis,angle,speed), MoveBy(axis,speed,distance) ... assigned to object or world ... But , i never had to calculate it manually, so i never got touched with this things.

So now i'll have a new try. When i get someting (also wehn its particular) to work, i'll place it at playgound and link it to here.

Link to comment
Share on other sites

I just tested the fly cam.

- I can slide forward, backward, left, right, up, down. (Moving on xyz axis)
- I can yaw and pitch directly with mouse
- I dindt find out how to roll directly with keyb or mouse
- There is a vertical-limit, when you try to pitch more then to stright up/downwards, it dont work because its limitated. (So you cannot "fly a loopong", you'll hang on vertical direction.)
  ... is there anything like at the arcrotatecam , to disable this limit?

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...