Hi,
I have a question about Physics engine.
I want rotate the physicsRoot,but this line ( physicsRoot.rotation.y += 0.1;) does not effect.
I have used unity,if I use physics engine,it can do well.
if I remove the line (physicsRoot.physicsImpostor = new BABYLON.PhysicsImpostor(physicsRoot, BABYLON.PhysicsImpostor.NoImpostor, { mass: 3 }, scene);),it can effect,however it has no physics effect.
I don’t know why? Can you help me? Thanks a lot!
The relative code as follow:
var createScene = function () {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.FreeCamera(“camera1”, new BABYLON.Vector3(0, 5, -10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight(“light1”, new BABYLON.Vector3(0, 1, 0), scene);
scene.enablePhysics(new BABYLON.Vector3(0,-10,0), new BABYLON.AmmoJSPlugin());
var ground = BABYLON.Mesh.CreateGround(“ground1”, 6, 6, 2, scene);
ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.7 }, scene);
// Import mesh and set colliders
BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) {
// Scale loaded mesh
newMeshes[0].scaling.scaleInPlace(0.01);
newMeshes[0].position.set(0,0,0)
var boxCollider = BABYLON.Mesh.CreateBox("box1", 0.3, scene);
// Create a physics root and add all children
var physicsRoot = new BABYLON.Mesh("", scene);
physicsRoot.addChild(newMeshes[0]);
physicsRoot.addChild(boxCollider);
physicsRoot.position.y+=3;
physicsRoot.rotation = new BABYLON.Vector3(0,Math.PI/2,0);
// Enable physics on colliders first then physics root of the mesh
boxCollider.physicsImpostor = new BABYLON.PhysicsImpostor(boxCollider, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0 }, scene);
physicsRoot.physicsImpostor = new BABYLON.PhysicsImpostor(physicsRoot, BABYLON.PhysicsImpostor.NoImpostor, { mass: 3 }, scene);
setInterval(()=>{
physicsRoot.rotation.y += 0.1;
},100)
});
return scene;
};