Havok is causing Havoc

I’m really struggling with getting things moving :slightly_smiling_face:
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;}

How are trying to move your bullets, With physics forces or manually moving the transform…?

It looks like you are setting the motion type to Animated (Which is really Kinematic). That mean you move the object with regular translation code (I think).

If you wanna reliable move with applyForce or applyImpulse you need to use Dynamic Motion Type.

Me personally, love Havok Physics… I have a Character Controller that i originally used ANIMATED as the motion type, but i would have to do all the Collide And Slide movement for collision detection.

I ended up just applying the velocity directly using SetLinearyVelocity and SetAngularVelocity

Here is a Havok Physics based example playground using my Babylon Toolkit that loads a SampleScene level with all the scene environment. Then it loads a Player Armature model, attaches a Third Person Player Controller and uses my UNITY.CharacterController component to move the player around using physics

Character Controller Demo

1 Like

In addition to what @MackeyK24 said, you also have to set

bullet.physicsBody.disablePrestep = false

before you set position directly. I say “before” in case you’re setting position in an async function, because you don’t want a physics frame occuring between setting position and setting disablePreStep.

2 Likes