Jump to content

Collisions with an animated object


Caterina
 Share

Recommended Posts

Hi everybody!
I've just started using Babylon.js for a small project for an exam, but I'm having some troubles...
I have a box that moves pressing arrow keys; when it collides with a fixed object, as a wall, the game ends. This part of the project works, and I've used the intersectMesh method to do this. The box moves updating its position each time that a key is pressed. (I don' t know if this is important but the box has a physics state, in order to properly move on the ground, that is made with an height map).

Now, I'd like to add some small objects that the box can "collect" while moving, just colliding with them. I've created my meshes and I've added two animations, one for position and one for rotation; if I try to use the intersectMesh method for the box and the new mesh, it simply doesn't work...

Can someone please explain me why this doesn't work? Thank you! :)

Link to comment
Share on other sites

Here I've done a simplified scene of what I'd like to obtain... the blue box moves and rotates with arrows; when it collides with the wall (other box on the right) the blue box becomes red; if the blue box collides with the sphere, it doesn't change its color, while I want that it becomes green.

http://babylonjs-playground.com/#1AV6FK#0

Edited by Caterina
Wrong link, I'm sorry
Link to comment
Share on other sites

Actually it works but you cannot do the collision test when hitting keys because at the time I press a key the sphere could be outside of the box and if I do not press the key again I won't be able to detect the collision

You have to check the collision on every frame (using scene.onBeforeSceneRender for instance)

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.

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

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...