Create Physics Engine Objects,the objects will fly at the begin of game

Hi,I have a question about Physics engine.I create five cars mesh to display in the game scene,but at the begin of the game,these cars will fly to the sky? If I only create one car,all is ok? The distance of cars is enough big,and they don’t collide each other.I don’t know why?
If I only call CreateMainPlayer(), all is Ok,but if I call CreateOtherPlayers(),all the cars flys to the sky.
I use the physics engie with CannonJSPlugin. And here is the source code:

// add the role
private CreateMainPlayer()
{
let curMap = gameDataMgr.curSceneMap;
let mainPlayer = playerDataMgr.AddGamePlayer(curMap.playerPt,curMap.playerRot,3,this.scene);
mainPlayer.mainPlayer = true;
playerDataMgr.mainPlayer = mainPlayer;
}

//add four other players
private CreateOtherPlayers()
{
let carSpanWidth = 50;
let carSpanHeight = 70;
let mainPlayer = playerDataMgr.mainPlayer;
let playerPos = mainPlayer.playSelf.position;

    let postion = new BABYLON.Vector3(playerPos.x - carSpanWidth,playerPos.y,playerPos.z - carSpanHeight);
    playerDataMgr.AddGamePlayer(postion,mainPlayer.playSelf.rotation,3,this.scene);

    postion = new BABYLON.Vector3(playerPos.x - carSpanWidth,playerPos.y,playerPos.z + carSpanHeight);
    playerDataMgr.AddGamePlayer(postion,mainPlayer.playSelf.rotation,3,this.scene);

    postion = new BABYLON.Vector3(playerPos.x + carSpanWidth,playerPos.y,playerPos.z - carSpanHeight);
    playerDataMgr.AddGamePlayer(postion,mainPlayer.playSelf.rotation,3,this.scene);
    
    postion = new BABYLON.Vector3(playerPos.x + carSpanWidth,playerPos.y,playerPos.z + carSpanHeight);
    playerDataMgr.AddGamePlayer(postion,mainPlayer.playSelf.rotation,3,this.scene);
}

//function of adding player to the scene
AddGamePlayer(playerPos:BABYLON.Vector3,playerRot:BABYLON.Vector3,prefabId:number,scene:BABYLON.Scene):void
{
let curMap = gameDataMgr.curSceneMap;
// Create a physics root and add all children
let carDefault = gameDataMgr.carPrefabs[prefabId].node as BABYLON.Mesh;
let playerSelf = new BABYLON.Mesh(“Player”,scene);
let carMeshInst = carDefault.createInstance(“Player”);
carMeshInst.rotationQuaternion = new BABYLON.Quaternion();
playerSelf.addChild(carMeshInst);

    let boxCollider = BABYLON.Mesh.CreateBox("Collider",1,scene);
    boxCollider.position.y = 5;
    boxCollider.position.z = -9;
    boxCollider.scaling = new BABYLON.Vector3(15,8,38);
    playerSelf.addChild(boxCollider);
    // Enable physics on colliders first then physics root of the mesh
    boxCollider.physicsImpostor = new BABYLON.PhysicsImpostor(boxCollider,BABYLON.PhysicsImpostor.BoxImpostor,{mass:0},scene);
    playerSelf.physicsImpostor = new BABYLON.PhysicsImpostor(playerSelf,BABYLON.PhysicsImpostor.NoImpostor,{mass:5},scene);

    boxCollider.isVisible = false;
    playerSelf.position = MathUtil.CloneVector3(playerPos);
    playerSelf.rotationQuaternion = BABYLON.Quaternion.FromEulerVector(playerRot);
    
    playerSelf.isPickable = false;
}

Pinging @Cedric

Hi @shhuangcheng

I didn’t anything weird in your code. Can you repro the behavior in a playground, it would be way more easier.

Besides that, did you try to use ammojs instead of Cannonjs ? Can you try to comment some code (I’m thinking of addBehavior) to see if you can narrow the source of the issue.

Do the cars fall after a while ? If they do, then it might be a property set at construction time, or a collision/joint issue. Do you have joints? Can you disable them and see what you get?

What happens when you create the player + only 1 car ?

The behavior has no effect.I remove these code,and the cars still fly to the sky.
These codes is simple.The function of CreateMainPlayer() is just add main role to the scene,and the function of CreateOtherPlayers() is to add four player to the scene.The function of AddGamePlayer(…) is to add player to the scene.
If I only call the function of CreateMainPlayer(),all is ok,the car(player) can run well.But if I alse call the function of CreateOtherPlayers(),the players(cars) will fly to the sky.

If I replace the physics engie with oimo,all is ok. I think it is the physics engine of cannonjs’s problem.

Yes, this looks like a bug. Can you please make a playground that reproduces the issue? I tried to do one but didn’t get the desired behavior. Thanks :slight_smile: