Jump to content



Recommended Posts

Hello html5gamedevs.com community,


This is my first post. Nice to meet you all. 

I am in the process of learning BabylonJs, it seems to be the most friendly to lazy beginners like me. I'm learning by trying to build some crazy stuff that crosses my mind.

For now I'm trying to fly:



I have the defaults moveZperSec=5; and camera.rotation.y = Math.PI / 4. The camera should look forward not on the right.

It seems that  camera.position.z is acting like the first time when the scene is created. Like you would always face north in a car regardless the turns the car makes just because you were facing north when you started the car.


Thank you.





Link to comment
Share on other sites

Yes, its own world. Because now is like I have a head and a body and only the head turn on the y axis. Eventually I will learn how to express myself in 3d :).

I'll take now step by step your last sentence.

How do I inverse camera world?

Has to do something with camera.upVector?

Link to comment
Share on other sites

I did not try camera.parent = mesh yet, I'll have to play around to see how that works. Hopefully if I attach the camera to an invisible mesh then when I rotate/move the mesh I get the desired result.

Meanwhile I just realized that probably, for the camera, the only way to always look ahead regardless of the rotateY is to share the speed of moveZ with moveX according to how much rotateY is, then I have to do the same for rotateX, split the speed of moveZ with moveY. That's some crazy math I have to do there unfortunately.

It would be cool to exists something like BABYLON.FlyCamera("Camera", new BABYLON.Vector3(0, 0, 0), scene) and the position actually to be the offset, so if position is 0,0,0 you rotate around yourself with rotation.y but if offset is 0,0,-10 you rotate around something that is -10 away from you similar to ArcRotateCamera. I would look later if I can post this as a future request, because is just cool.

Link to comment
Share on other sites

The follow camera is not a proper choice in this case. Playing around with it, the camera follows the mesh but has a mind of its own, in my imagination appeared a  situation when you follow a bird going above your head in the sky.

The best choice I find until now is camera.parent = mesh: http://www.babylonjs-playground.com/#ZJ5KL#2 , especially because I don't have to use camera.upVector = new BABYLON.Vector3(camera.rotation.z,1, 0) to rotate on z, but I still have to make those calculations to appear that I am in my own world, unfortunately. 

On the other hand Jedi BabylonJs Master @Deltakosh liked my post when I suggested a fly camera, who knows maybe in a future version of BabylonJs a fly camera will exist.


Link to comment
Share on other sites

If you mean you wish a camera to move forward (in the direction it is pointing) I can / am doing this, but you are going to need to wait a couple weeks.  Can also move in any of the POV direction combinations simultaneously:  (forward / backward), (up / down), & (left / right).

The way I currently have it, you would need to have the Queued Interpolation extension.  You have your own beforerender & are interactively doing it, not queuing an animation. To work the exact way you have it without QI, I would need to move a small amount of code to BJS itself (basically POV functions for TargetCamera & the 2 directional lights).  Would force 2.5 for QI.  Will have to think about that.

Link to comment
Share on other sites

Thank you  @adam to point me in the right direction. I would have never guessed the way you did it. I can't say that I really understand what happens there, but it works. Really much appreciated. @JSPalmer I have no problem waiting a couple of weeks, I'm not in a hurry, you do what you think is right.

My PG:


I actually move a box there with all the meshes inside of it, not the camera. I'm not sure if this is how you do it but I think you get in trouble with the perspective if you go to the end of the scene, so, I move the "world" not the camera.

The only think I will need to modify is the offset. Now I move away the camera to create the offset, although makes more sense to move the axes of the offset from the camera, but I'll see this later.

Thank you all for all the help, most definitely is a very friendly community.

Link to comment
Share on other sites


If the "ship" is rotated on z, rotation.y is not rotating on horizontal from the "ship" point of view, the same for rotation.x(not rotating vertical from the ship point of view)

The spinning should be horizontal:


I know I have to do something similar like in here:

var cameraRight = ship.getDirection(BABYLON.Vector3.Right());
var cameraUp = ship.getDirection(BABYLON.Vector3.Up());
var cameraForward = ship.getDirection(BABYLON.Vector3.Forward());
world.position.addInPlace(cameraRight.scaleInPlace(controls.moveX / 200 * animationRatio));
world.position.addInPlace(cameraUp.scaleInPlace(controls.moveY / 200 * animationRatio));
world.position.addInPlace(cameraForward.scaleInPlace(controls.moveZ / 200 * animationRatio));


Link to comment
Share on other sites

  • 3 months later...

Hello again, I have the time now to make the project with BabylonJs so I have the next challenges:


Thanks to @adam the "accelerate" controls work as they should be (the camera is in its own world). 
1. Now I want to make the same thing happen to the "translate" controls (doesn't matter that dat gui has only integers into those fields and the camera will jump, I'll adjust afterwords). Idea is to += the value from "translate" controls to the current XYZs.
2. In the "log" I see nothing for the mesh.rotation and I don't know why.




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