Jump to content

Move by steps with collisions


Recommended Posts


I would like to create game, where is possible move camera only by predefined steps from square to another square.

Here is sample what I want:

playground steps example

When i try to move with default babylon arrow keys, collision works fine. But when I use my step keys (W A S D), collisions are ignored.

And another variant which I would like to use are predefined steps with move animation:

playground steps with animation example

Is there any way how to detect collisions with animation?


Link to comment
Share on other sites

Well it looks my question is stupid or not understandable, sorry about my english.

Probably problem is, that I use my own keys for movement so babylon doesnt fire default events with collisions? Can I hook this events myself?

About animation movement I was thinking that instead of animation I can set velocity and call MoveWithCollisions, but it looks it is not working with camera, only with objects. Or is there solution how to use it with camera?

Thanks for your help

Link to comment
Share on other sites

10 minutes ago, RaananW said:


If you want to add WASD instead (or together with) the arrows, simply add them to the keys arrays. for example check how I added the 'w' key (code 87) to the keyUp array (line 17) - http://www.babylonjs-playground.com/#19SAQS

Now 'w' works as forward.

Is that what you wanted?


thanks for your reply.

I used WASD keys because I dont want use continuous movement, but move by predefined steps, you can imagine it as moving on chessboard. I want to jump from centre of one square to centre of another squre directly.

I suppose for arrow keys there is some low value, for steps for example 0.01, but I want to do step for example by 5.

I think, that in this case collisions are not fired, because I jump over collision detection area.

Link to comment
Share on other sites

1 hour ago, RaananW said:

How about changing the camera's speed? http://www.babylonjs-playground.com/#19SAQS#2

Hi, thanks, this looks like possible solution. :)

But can you please check why in this sample http://www.babylonjs-playground.com/#19SAQS#4 works collisions on move left (green) or right (red) planes, but not when I go forward (blue plane)?

Is there any way to use html buttons for movement instead of arrow keys? Can I fire arrow key press event from javascript?


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