Jump to content

Car demo apply collisions


nodejs
 Share

Recommended Posts

Hello,

i played with the car demo on playground.
But im not able to apply collisions to the car.

Can anyone tell what i do wrong ? Playground
I added:

scene.collisionsEnabled = true; // Line 6
carBody.checkCollisions = true; // Line 104

// Also to the wheels
wheelFI.checkCollisions = true; // Line 96
wheelRO.checkCollisions = true; // Line 92
wheelRI.checkCollisions = true; // Line 87
wheelFO.checkCollisions = true; // Line 82

// Cubes on ground
boxes.checkCollisions = true; // Line 138

But dosnt work, i dont know why.

Link to comment
Share on other sites

Wingnut goofing-around...

https://www.babylonjs-playground.com/#102TBD#51

SPS (solid particle system) might not have ellipsoid collision features available... on the particle shapes.

SO... I said goodbye to SPS particles, and I changed to boxes... more standard.

I added 2 util funcs at the top... used to help "see" .ellipsoids.

I do much INIT of the car part 'ellipsoidMesh'... in lines 169-188.  The .ellisoidMesh is NOT PROOF that a collider is present on a cloned or instanced mesh.  It is simply a wireframe sphere FORCED into the scene.  It has to be told to track the non-rendered .ellipsoid Vector3 and collider.

So, lines 339-350, inside an "afterRender" loop, I attempt to get the carBody and wheels 'ellipsoidMesh' (the wireframed spheres)... to "turn with" the car and its wheels... as you drive around.  I am not very good at copying rotationQuaternions from actual mesh... into ellipsoidMesh.rotationQuaternion, so work is needed, there.

And, I haven't seen ANY collisions, yet.  Maybe soon... with the help of others.

Keep in mind that the built-into-BJS collision/ellipsoid system... was designed for camera->mesh collisions... and NOT for mesh->mesh. 

Perhaps... it is time to think about a feature called 'intersectsMesh" (using that to write your own collision checking "loop"), or perhaps use a 3rd party physics engine.  BJS has plugin support for 2-3 of the best physics engines.

There is ONE box that is not a clone (it looks different - expected).  It is the clone's master.  I create all the boxes in line 215 area.

Still testing... playing... see if I can understand some things.  DON'T TRUST .setEllipsoidPerBoundingBox() or .showEllipsoid() to be accurate or indicative of anything.  They are badly coded... by me.  :)  I'm pretty sloppy and forgetful.  But perhaps, used with caution... they can be temporarily helpful.  

Others will likely comment soon.  Perhaps somebody can help keep my Wingnut-added wheel.ellipsoidMesh... properly rotated to match car items (lines 339-349).  thx

Link to comment
Share on other sites

https://www.babylonjs-playground.com/#102TBD#53

A little better.  .ellipsoidMesh are tracking the mesh a little better.  No problems with car turns.

I don't think there is any collision-testing activated in these playgrounds.  This playground doesn't use .moveWithCollisions at all, so there's no "reaction" to collisions.

With .moveWithCollisions(someAmount), the mover quits when a collision happens.  But here, there is nothing to tell the move-system... that a collision has happened and to do some reaction (such as quit movement immediately, or explode the collided-with thing.  :)

So, collisions ARE likely happening.  Just no "reaction" has been programmed, yet.  (such as an onCollide() func).  This thing is ready to PARTY, I suspect.  Let's blow up some obstacles!

I think line 321 is the forward mover.  pivot.translate(BABYLON.Axis.X, -distance, BABYLON.Space.LOCAL);

Let's try changing that... to a moveWithCollisions() mover.

https://www.babylonjs-playground.com/#102TBD#55

Lines 323-335 is the experimentation area.  I try some "micro" moveWithCollisions on the 5 main body parts.  (They are all parented to pivot so I don't want to move them away-from their parent too far.)  Moving is working fine, but, no joy for collisions.  A fun challenge, so far.  Still thinking and testing. 

Remember... the "look" of the wireframe spheres... is NOT necessarily the correct .ellipsoid size/position.  Verify with console.log(someMesh.ellipsoid);  My goofy .setEllipsoidPerBoundingBox() could have mistakes.

Link to comment
Share on other sites

On 11.11.2017 at 4:13 AM, Wingnut said:

Keep in mind that the built-into-BJS collision/ellipsoid system... was designed for camera->mesh collisions... and NOT for mesh->mesh. 

I didnt know that

 

On 11.11.2017 at 4:13 AM, Wingnut said:

 perhaps use a 3rd party physics engine.  BJS has plugin support for 2-3 of the best physics engines.

This was the next step, but first i would play a litle with collisions.

 

I must play a lot more with BJS to reach my goal -_-

Thank you very much

Link to comment
Share on other sites

Hi again, NJS! 

   Well, I was sort-of hoping that other forum helpers would help work-on the colliders, but, they haven't.

Perhaps today, I will try some more things.  I think we also have the option-of actionManagers on the 5 car parts.  In the triggers section of ActionManager docs,  we have a BABYLON.ActionManager.OnIntersectionEnterTrigger.  " Raised when the mesh is in intersection with another mesh. Raised just once."

That sounds kind-of good, huh?  Using actionManager OnIntersectionEnterTrigger would allow us to avoid .checkCollisions and mesh.ellipsoids.

ActionManagers are generally 2-part things... a trigger and an action.  We have our "OnIntersectionEnterTrigger" for the trigger, but we would need an action.

One of my FAVORITE actionManager actions... is executeCodeAction.  Unfortunately, there is no example of executeCodeAction in our playground ACTIONS demo

A playground search for executeCodeAction does MUCH better, returning 331 "hits".

When using an executeCodeAction and the actionManager triggers, it executes a pre-declared function.  Lets call our function... onCarHitSomething(bjsEvent).

That bjsEvent parameter arrives at the action-function automatically (sort of like DOM event object that automatically arrives-at webpage-like event handlers).

I think that bjsEvent object has a property on it... named .source.  I THINK .source... will contain the mesh that the car HIT.

So, inside our pre-made onCarHitSomething(bjsEvent) {  bjsEvent.source.position = explosion AND bjsEvent.source.dispose()  }   (that's pseudo-code, of course) :)

You get the idea.  Perhaps using ActionManagers will do better for sensing collisions... than the .checkCollisions/.ellipsoid system (IF blowing-up/disposing obstacles after impact).

IF you want the obstacles to slide or tumble across the terrain based-upon the force of the impact, then 3rd party physics engine is the better choice.

Ok, I'll get some morning coffee and re-read this post... make sure I didn't say too many wrong or stupid things (I do that sometimes)  :)

If you have questions, just ask.  If you want to tell me/us MORE about what you want to try, we will listen, and try to suggest the best ways.

Perhaps, in a few hours, I, you, or another forum helper... will activate an actionManager or 5... on our car... so we can do some tests/play.  :)

Talk soon.

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