Caterina Posted September 7, 2016 Share Posted September 7, 2016 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! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 7, 2016 Share Posted September 7, 2016 Hello, Are you using the physic engine to move your mesh? (I mean, are you calling mesh.applyImpulse?) the best way to help you will be to provide a sample in the Playground, so we can see your example live. Quote Link to comment Share on other sites More sharing options...
Caterina Posted September 7, 2016 Author Share Posted September 7, 2016 (edited) 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 September 7, 2016 by Caterina Wrong link, I'm sorry Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 8, 2016 Share Posted September 8, 2016 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) Quote Link to comment Share on other sites More sharing options...
Caterina Posted September 9, 2016 Author Share Posted September 9, 2016 Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.