Why bullet intersects ground and box when I don’t shoot at them?
Your code is a little difficult to unravel, however if you check this PG https://playground.babylonjs.com/#HFS0I0#2 you will see that the intersection of the box and ground occurs at the point of creation of the bullet. Its position on creation is such that it intersects the box and ground.
You may also be interested in reading about events in Babylon.js Interact with a Scene - Babylon.js Documentation
It seems that update .position of mesh …takes place in the next frame
.computeWorldMatrix() solves this
And another question.
How to make the bullet fly faster?
bullet.position.addInPlace(direction).scale(10);
You might want to think about
if (bullet.getDistanceToCamera(camera) >= 50) {
bullet.dispose();
scene.unregisterBeforeRender(foo);
}
rather than
if (bullet.getDistanceToCamera(camera) >= 50) {
bullet.material.diffuseColor = new BABYLON.Color3(1, 0, 1);
scene.unregisterBeforeRender(foo);
}
This seems like a bug to me. I opened a PR to do this automatically.
It didn’t work to me
Sorry brackets in wrong place
bullet.position.addInPlace(direction.scale(10));
Thanks, it helped 