my code :
**
import { Animation, ArcRotateCamera, Engine, HavokPlugin, MeshBuilder, PhysicsAggregate, PhysicsBody, PhysicsMotionType, PhysicsShapeType, Scene, Vector3 } from “@babylonjs/core”;
import HK from “@babylonjs/havok”;
const canvas = document.getElementById(‘app’) as HTMLCanvasElement;
const engine = new Engine(canvas , true , {} , true);
const createScene = async function () {
const scene = new Scene(engine);
const hk = await HK();
const havokPlgin = new HavokPlugin(true , hk)
scene.enablePhysics(new Vector3(0 , -9.8 , 0) , havokPlgin)
scene.createDefaultLight(true);
const camera = new ArcRotateCamera(‘cam’ , 0 , 1.2 , 5 , new Vector3(0 , 0 , 0));
camera.attachControl(true)
const ground = MeshBuilder.CreateBox(‘ground’ , {
width : 25,
depth : 2
} );
const player = MeshBuilder.CreateBox(‘player’ , {size : 0.5});
player.position.y = 1;
player.position.x = 3;
const playerBody = new PhysicsBody(player , PhysicsMotionType.ANIMATED , false , scene);
playerBody.setMassProperties({mass :1})
const playerParent = MeshBuilder.CreateBox(‘playerParent’ , {size : 0.5});
playerParent.position.y = 1;
playerParent.position.x = 3;
player.setParent(playerParent);
console.log(player.parent);
ground.position.x = -7;
const groundBody = new PhysicsAggregate(ground , PhysicsShapeType.BOX);
const playerAni = new Animation(‘moveForward’ ,
‘position.x’ , 30 , Animation.ANIMATIONTYPE_FLOAT , Animation.ANIMATIONLOOPMODE_CONSTANT);
const keyFrames = [
{
frame : 0,
value : 2.5
},
{
frame : 360,
value : -50
}
]
playerAni.setKeys(keyFrames);
playerParent.animations.push(playerAni);
scene.beginAnimation(playerParent , 0 , 360);
return scene;
};
const scene = await createScene();
engine.runRenderLoop(()=>{
scene.render();
});
window.addEventListener(‘resize’ , ()=>{
engine.resize();
}); **
i’m just trying to create a game i which there is a ground on which player moves forward and there are many enemies if player collide with any enemy game will end.