Projectile Collisions and Animations in BabylonJS Questions

I have a simple game that has one projectile Mesh colliding with an enemy Mesh. I am using a CreateAndStartAnimation:

Animation.CreateAndStartAnimation( "anim", projectile, "position", 30, 4, player.position, 
  enemyCoordinates, Animation.ANIMATIONLOOPMODE_CONSTANT, undefined, 
   () => { if (pickedEnemy)
            if ( collideEnemyAndProjectile( pickedEnemy, projectile ) ) 
              { enemyList.forEach((enemy) => {
                             if ( pickedEnemy &&pickedEnemy.id == enemy.getEnemyId() ) enemy.damage(34);
                             if (!enemy.isAlive()) { pickedEnemy?.dispose();
                               enemy.destroy(); }
                           });}
                       projectile.dispose(false, true);
  }
);

With my current implementation, the projectiles don’t always trigger a collision when they do hit (maybe 80% of the time it works). My guess is because this is an animation of the sphere and it is not present on the screen for every single frame?

Also, the other problem, is that the projectile does not always shoot to the point where the enemy is in real time; it shoots to where the enemy was. This is what the collideEnemyAndProjectile function looks like:

export const collideEnemyAndProjectile = (
    enemy: AbstractMesh,
    projectile: Mesh
) => {
    if (projectile.intersectsMesh(enemy, true)) {
        return true;
    } else {
        return false;
    }
};

Is the “intersectsMesh” function the best one to use here?

Any feedback is very much appreciated. Thanks in advance!

Oh and if any of the code doesn’t make sense, feel free to ask. I am happy to respond!

Pinging @Cedric

@shawn-p-m If the enemy moves after enemyCoordinates is passed as the to parameter in CreateAndStartAnimation, then I think the bullet will continue towards enemyCoordinates (enemy’s past position) instead of the enemy’s current position, as you had mentioned

We would need to find a way for your bullet traveling logic to account for enemy position updates

Yes, that’s right.

I’m wondering if there is some function other than CreateAndStartAnimation that can do that sort of thing?