I’m really struggling with getting things moving
If I create an instance and apply a impulse it works fine.
If I create an instance and apply a impulse at a later time, it doesn’t move.
What am I doing wrong ?
I’m using this function to create the bullets.
function createBullets(){
numbullets=0;
while (numbullets<maxbullets){
firedBullet[numbullets] = bullet.createInstance(“firedBullet_”+bulletCount);
firedBullet[numbullets].checkCollisions = true;
firedBullet[numbullets].isVisible = true;
fbAggregate[numbullets] = new BABYLON.PhysicsAggregate(firedBullet[numbullets], BABYLON.PhysicsShapeType.SPHERE, { mass: 0, restitution: 0 }, scene);
console.log(“Created Bullet “+numbullets+” X:”+firedBullet[numbullets].position.x+" Y:“+firedBullet[numbullets].position.y+” Z:"+firedBullet[numbullets].position.y);
numbullets++;
}
}
Then Im trying to fire them using this …
firedBullet[bulletCount].position.x = camera.position.x;
firedBullet[bulletCount].position.y = camera.position.y;
firedBullet[bulletCount].position.z = camera.position.z;
firedBullet[bulletCount].isVisible = true;
fbAggregate[bulletCount].body.setMotionType(BABYLON.PhysicsMotionType.ANIMATED);
fbAggregate[bulletCount].body.setMassProperties({mass: 0.1, restitution: 0.1});
fbAggregate[bulletCount].body.applyImpulse(camera.getDirection(BABYLON.Vector3.Forward()),firedBullet[bulletCount].absolutePosition);
console.log(“Firing Bullet “+bulletCount + " X:”+firedBullet[bulletCount].position.x+” Y:“+firedBullet[bulletCount].position.y+” Z:"+firedBullet[bulletCount].position.y);
console.log (camera.getDirection(BABYLON.Vector3.Forward()) );
bulletCount++;
if (bulletCount>=maxbullets){bulletCount=0;}