Incorrect body's collision

Please help me deal with the question. I always have some problems with this machine :slight_smile:

PG: https://www.babylonjs-playground.com/#510DL5#2

Immediately the box, which is tied to the car, knocks the balls. But as soon as she drives a little, collisions no longer occur and the car screams through the balls.

Initially, the balls at least react to the box, but there are no machine parts themselves, why?

Piinging @cedric

Like 149 of your PG, you’re parenting the mesh (box1) with the chassis. Line 150, you are creating a new impostor.
After that, the impostor’s transform is not updated.
Usually, physics engine/impostor is used to control the car. Not the reverse where an impostor is linked to a mesh.
You can try to update the impostor transform before each frame is rendered.

 scene.registerBeforeRender(function () {
    box1.physicsImpostor = new BABYLON.PhysicsImpostor(box1, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 });
 })

right?

Impostor will be created each frame. Might be overkill but it should work.
I don’t know how the garbage collection will work.
Call removeImpostor maybe before adding a new one.

My new PG: https://www.babylonjs-playground.com/#1HF9GP#1

I left physics only with the parent and the box. And it works … but not completely. For some reason, the car still doesn’t work reacts to walls (passes through them). And collisions with balls are also not natural

PG: https://playground.babylonjs.com/#8ULU6G

I’ve worked a bit on the code, and now the walls can block the car’s movement, but when it falls into the balls, a mess begins

What am I doing wrong?

Take a look at this PG, I think it does what you want and you can use it as a starting point:
https://playground.babylonjs.com/#609QKP#2

I saw this example, but there are used some methods of a specific ammo engine. I don’t understand their essence and can’t rewrite for my needs

Which methods? I may be able to explain them

all methods that begin with the word Ammo

Basically, You create shapes (btBvhTriangleMeshShape, btTriangleMesh). That’s used to test and report contact points. Then, for dynamic objects(chassis, wheels,…) you create one rigidbody (btRigidBody). The rigid body is responsible for transforming contacts into velocity and torque to objects.
BulletPhysics/Ammojs provide an helper objects for vehicles. instead of doing everything manually (shapes, bodies, joints), it create everything you need with a few calls:

var tuning = new Ammo.btVehicleTuning();
var rayCaster = new Ammo.btDefaultVehicleRaycaster(physicsWorld);
vehicle = new Ammo.btRaycastVehicle(tuning, body, rayCaster);

One the physics objects are in place, rendered meshes position and orientation are updated each frame from the rigid bodies Line 128-200 and more specifically lines 182-198.

The interaction between the keyboard and the physic objects are line 169-178. Depending on key pressed, forces are applied to the vehicle.

Theworkflow for physics is always the same (using ammojs directly or thru impostors): you apply forces/torque to physic objects. Physics objects respond to forces and contacts. Physics objects matrices are then applied to rendered mesh (manually in this case or handled by the engine like with the impostors in Babylonjs)

Let me know if you have more questions

image

I tried to transfer the game code. Used a webpack. And I got an error … so I didn’t want to use these obscure methods