How can I get the camera to move forward and backward (custom input)?

Hi there, I am hoping that this is simple. In my playground I have a simple scene. I want to move the camera forward and back using the arrow keys. I want this to be slower than the default. I changed the number at line 27 to 38 thinking this would have the desired result, it didn’t. I am having a hard time finding a slow-moving camera where I can move and look all around using the mouse, and forward back keys.
Any help would be nice.

hey, I think what you need is to use scale when moving, like:


You can use Forward(), Backward(), Right(), Left() for movments.

Dshah_H…thanks for your replay.

hey, did that solved for you? If not, do reply, this place is full of avengers to sort it out for you xD

Hi Dshah_H, sorry no…it didn’t really work for me. I am new to programming, so I wasn’t sure how to use your code. At present I am just scouring the playgrounds to find what I am looking for. I found one that worked a tad better for me (still isn’t exactly what I want though). Ideally, I want the camera to move around a ground plane, be able to spin around, look up and down on its own axis…and do it smoothly (ideally all with the mouse).

I will shortly be uploading a new problem that may interest you.

Cheers…and thanks for getting back to me. :smile:

If you want to use mouse, I think you should use GUI. here is an example, which you can use to move with mouse you can extend it for more functionalities

and since you mentioned you are new to programming, I strongly suggest to check examples but try to read related docs, it will help you in the long run.

1 Like

I guess it starts by choosing the type of camera you want/need. In your PG you started with an arc rotate camera. Than you added all sorts of cameras and input that would hardly work together;)
A rule of thumb of mine: When the code becomes too long and complex, it’s likely to be shit code;) And I know a lot about ‘shit code’ being essentially a designer :grin:
The arc rotate camera does not move ‘forward’ or ‘back’ therefor the scaling of the camera as proposed will not work with this type of camera. Though the code of @Dshah_H would work with a moving camera. You could simply copy/paste it. The other thing for a ‘smooth camera’ is the scaling. You are using a very small ground and object/cube. The camera sensitivity will improve a lot if you start by using a more appropriate scaling for your scene.
Next, here is a simple example of the basic camera settings you can set on an arc rotate camera.
You will also be able to bind other keys than the default and apply the same sensitivity (or a different sensitivity with a multiplier) than for your mouse. In which case both your mouse and keyboard inputs will use your settings…
And since you are new to BJS, my advise would also be to take some time to visit the doc to get at least a basic understanding of how cameras work.
Happy discovery and happy coding,

Hi Dshah_H and mawa, all good advice…thanks for your replies.

Yes, it is early days for me using Babylon.js, so I am all over the place, using blunt instruments, trying to get things to work. I have learnt a lot from this approach, and I am now starting from scratch…with sharper tools.
Thanks again for your useful information. :smiley:

Yes, well I can tell you I did this just a little more than a year ago. Meanwhile, the doc have been updated and enhanced. I’m not really new to programming, but I’m just low to slightly above average in a variety of programming (since 3 decades;). I’d usually leave the complex and backend parts to the true devs. But for once and with BJS, I wanted to make the additional effort (so that I better know what sort of effort I’m requesting from the devs;) At least that. On the other hand, things like the handling of camera is clearly on my side (on the designer side) in the first place, in my opinion.

You’ll find that BJS is, according to the tagline ‘simplicity reimagined’, a framework that is welcoming new users. Yes, you will need to invest a bit of time and effort but you will also be rewarded (and sometimes quickly rewarded with just 1 line of ‘saber code’:crossed_swords: :boom:. BJS can let you do incredibly simple things that look and work perfectly thanks to the philosophy, method and direct approach. Again, my opinion only.

The docs are comprehensive, the playground and the community are invaluable assets for both newcomers and experts.
Have a great time with BJS, Cya,

1 Like

Hi mawa, thanks for your post.

Yes, the playground and the community are great. I am going to put the time in, as I hope to create some interesting work in the future. I’m committed to the two Bs…Blender and Babylon.

Cheers :smile:


Yup, a ‘reasonable’ and ‘consistent’ choice of tools (again, my opinion only)