Hi, I cant find a “c#” script for this… im making a turret defense game, the enemies in a determinate points they change their direction (random), i need a parabolic shot to a moving target with unpredictable direction movement.
I suppose that i will have to make corrections during airtime…
This is a really tough question. Evalutating the right values for a mathematical function to let it go through a target souds very hard and complex. I am not sure if there is a mathematical solution for it.
what I would do is using the binary search with your variables until you find a working setup. This would be easy if you had only one variable… but you have more, so it will become a bit tricky… good luck
Since it sounds like you want all of your arrows to hit the targets (eventually), I’m assuming then this is primarily for visual effect, and not some sort of Ai that attempts to target randomly moving objects.
Since most tower defenses are descendants of Warcraft 3, I booted up the map editor for that game to see how they do it. Basically, it will calculate the initial parabolic equation (which is easy enough to do). If the target unit begins to move, it will rotate the arrow to keep facing the target. If the target is moving away from the shooter (and therefore father away from the initially calculate landing position), when the arrow reaches the Y height that it was supposed to (and where the target “should” have been) land, it sets the gravity on the arrow to zero and chases after the target like a homing missile at a constant height.
I’ve had the game since it was launched in 2002 and never noticed this, so it looks pretty convincing!