You could for example make it so that after a while (like 10 ticks) it despawns immediatesourceentity and spawns an identical entity that flies and is programmed to attack certain mobs (though I don't think you can do this to players since it would treat you and other players as the same species of entity). After it collides with an entity that is not the player, it despawns.
You could also make it so that the projectile only when it detects an entity to attack in a specific radius despawns and spawns in that custom entity I mentioned
sooo lock onto players, mobs? we need more information
players and mobs
You could for example make it so that after a while (like 10 ticks) it despawns immediatesourceentity and spawns an identical entity that flies and is programmed to attack certain mobs (though I don't think you can do this to players since it would treat you and other players as the same species of entity). After it collides with an entity that is not the player, it despawns.
You could also make it so that the projectile only when it detects an entity to attack in a specific radius despawns and spawns in that custom entity I mentioned
You have to use update tick in the projectile procedure for both of these solutions
Just apply a force in the direction of the closest entity...