DesignVibe Posted March 16, 2016 Share Posted March 16, 2016 Hi guys I've "nearly" completed a project and come to a stage where I have a height map and a flying steampunk ship ("yep I'm a steampunk fanatic") anyways, I have a stretched sphere surrounding the ship and I wish to use that as the collision point to the heightmap. I have used rays and it work really well but I would like more of a realistic collision i.e. When the ship hits a mountain head on, instead of going up and over the mountain I would like it to collide and to move left or right http://www.babylonjs-playground.com/#1L0CBO#2 I remember on a previous submission @RaananW made an impressive playground for a car to travel over a heightmap. which I tried to understand, however for a newbie its a little complex http://www.babylonjs-playground.com/#UGMIH#3 any help or advice would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
jerome Posted March 16, 2016 Share Posted March 16, 2016 When using a ground mesh, it is better to consider using getHeightAtCoordinates() and getNormalAtCoordinates() (if you need the normal to implement your own behavior) that are far more faster than the ray method http://doc.babylonjs.com/classes/2.3/GroundMesh#getheightatcoordinates-x-z-rarr-number http://doc.babylonjs.com/classes/2.3/GroundMesh#getnormalatcoordinates-x-z-rarr-vector3-classes-2-3-vector3- here is a demo of the use of these both methods : http://babylonjs.com/Demos/Boom/ Wingnut and DesignVibe 2 Quote Link to comment Share on other sites More sharing options...
DesignVibe Posted March 16, 2016 Author Share Posted March 16, 2016 Hi Jerome thank you for the fast feedback. I shall give that a very good try. tip of the hat to you Quote Link to comment Share on other sites More sharing options...
jerome Posted March 16, 2016 Share Posted March 16, 2016 thank you another shorter (in LOC) demo using getHeight and getNormal on a heightmap : http://jerome.bousquie.fr/BJS/demos/getHeightAtCoordinates.html DesignVibe 1 Quote Link to comment Share on other sites More sharing options...
DesignVibe Posted March 17, 2016 Author Share Posted March 17, 2016 Hi @jerome I have searched quite a few posts and found that you are the ultimate master of using getHeightAtCoordinates() and getNormalAtCoordinates(). I still find it a little confusing but with these posts I think I might be able to learn quite a few tricks: from what I've seen I really do like this system as it saves time and RAM but trying to understand how I can use it to detect a mesh colliding upon a key-press (with world/local translation) instead of an animation is a little over complex, I'm sure I'll get there though Quote Link to comment Share on other sites More sharing options...
jerome Posted March 17, 2016 Share Posted March 17, 2016 hope so courage :-) DesignVibe 1 Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 17, 2016 Share Posted March 17, 2016 Or use physics! If the (truly wonderful) mathematical solution is enough for you, use it. But if you need true collisions you will have to use the physics engine... Let us know if this is enough, and if not let's try using physics. Which is a lot of fun, once you know how it's done. Just like a good magic trick. 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.