Why bullet intersects ground and box when I don’t shoot at them?
1 Like
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
1 Like
It seems that update .position
of mesh …takes place in the next frame
.computeWorldMatrix()
solves this
2 Likes
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);
}
1 Like
This seems like a bug to me. I opened a PR to do this automatically.
3 Likes
It didn’t work to me
Sorry brackets in wrong place
bullet.position.addInPlace(direction.scale(10));
1 Like
Thanks, it helped