Brandenburg Posted April 19, 2016 Share Posted April 19, 2016 Hello Everyone, I just started working with Babylon JS a few months ago and so far it is great. Right now, I am working on a project where if you click on any given point the selected unit will move to that spot. What I need now is to be able to tell when a mesh collides with another mesh while it is moving to that spot(see video). Any ideas how I could do this? Is there a way I could call a function on_collide? I would greatly appreciate any help. collision.mp4 Quote Link to comment Share on other sites More sharing options...
Flomotion Posted April 20, 2016 Share Posted April 20, 2016 Hi, I think you can use mesh.moveWithCollisions(speedvector) for that. Quote Link to comment Share on other sites More sharing options...
iiceman Posted April 20, 2016 Share Posted April 20, 2016 Yeah, moveWithCollisions is a good start. If you want to control alot of units and want something more sophisticated and fancy check this out: http://visualiser.fr/babylon/crowd/ Quote Link to comment Share on other sites More sharing options...
Brandenburg Posted April 20, 2016 Author Share Posted April 20, 2016 3 hours ago, Flomotion said: I think you can use mesh.moveWithCollisions(speedvector) for that. In reply to Flomotion. Thanks for your reply. After looking into moveWithCollisions it looks like that might work. I have a couple of questions about it though. Normally I would create an animation to move a unit like this (shortened version): var positionAnimation = new BABYLON.Animation("testAnimation", "position", 150, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT; keys.push({frame: 0, value: positionVector1}); keys.push({frame: 40, value: positionVector2}); keys.push({frame: 80, value: positionVector3}); I would then play the animation to move a unit. From what I could see, it looks like the moveWithCollisions function will just move in a direction and not stop until it reaches an obstacle, any way you can just give it a point to move to? Also how do I control the speed with which this moves the mesh? If you could just point me to a link with the docs for this function that would also help but I couldn't find it on the Babylon JS site. Thanks again for all your help, Brandenburg Quote Link to comment Share on other sites More sharing options...
Brandenburg Posted April 20, 2016 Author Share Posted April 20, 2016 In reply to iiceman. Thank you for your reply as well. That plugin looks really cool I would probably use it if I was starting from scratch. I probably will just go with moveWithCollisions for now just because I already have a pathfinding plugin based on a grid that computes paths pretty fast, I just need moveWithCollisions for running into other units. Thanks, Brandenburg Quote Link to comment Share on other sites More sharing options...
Flomotion Posted April 21, 2016 Share Posted April 21, 2016 Hi, I understand what you want to do. I guess you have to calculate the angle of the end position for each mesh and check in the registerBeforeRender function if that position was reached. Meanwhile make the mesh move in the direction of the end point with a certain speed. I only used it to make an object move in the camera direction constantly. See section 4 of this tutorial http://doc.babylonjs.com/tutorials/Cameras,_Mesh_Collisions_and_Gravity Hope it helps! Brandenburg 1 Quote Link to comment Share on other sites More sharing options...
iiceman Posted April 22, 2016 Share Posted April 22, 2016 Very basic example playground here: http://www.babylonjs-playground.com/#KLPKS Hope that helps, let me know if you have questions about it Brandenburg 1 Quote Link to comment Share on other sites More sharing options...
Brandenburg Posted April 22, 2016 Author Share Posted April 22, 2016 Thanks both of you, I now have it working! The Tutorial, Playground and this Playground really helped me understand it. Thanks again for your help, Brandenburg iiceman, GameMonetize and RaananW 3 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.