-
What do I want to achieve?
I want to make it so projectile towers can predict where the enemy will be when their projectile gets to them. For example, a Grenadier tower that throws a grenade at the enemy position with the grenade speed being 10, but due to the enemy being able to move, it can sometimes miss it, so I want to make it throw the grenade right into the position where the enemy will be when the grenade lands. -
What is the issue? I simply cannot understand how to make it work. The problem there is that I need time to predict the enemy, but to get it I need to calculate distance between the tower and the enemy, which I cannot get without getting the position of the enemy.
This is probably possible without using time and rather using the distance between the tower and the enemy & projectile speed, but I don’t really know how to make it work, which is why I’m making this post.
My enemy system works using a single number between 0 and amount of positions the map has, using this number inside a lerp() function. So, for example, when the enemy would have Alpha of 1.5, it would be put in middle of Pos1 and Pos2.
Alpha gets increased from that formula: Alpha = Alpha + ((Speed / Distance) / 50) * PassedMultiplier,
with Speed being it’s own speed, Distance being the Distance between two Positions (Pos1 and Pos2, for example), PassedMultiplier being a check of how much time actually passed by task.wait(.01) using tick().
So far I tried multiple things, but none of them worked since none of them actually predict where the enemy will be.
What I actually need is to somehow get the predicted position of the enemy using: Enemy position, Tower position, Distance between the tower and the enemy, and projectile speed. If someone can help me, thank you.