Hello! I’m trying to figure out how to add a new attack style to my AI Enemy.
Instead of trying to explain everything, I found an image that kinda exactly explains what I would want the AI to do.
Problem is I am not at that math level, so I have no idea what I’m looking at!
I found the image from this link:
Get the “velocity” of the target player. Multiply by the time the bullet will take to travel to the target. Then get the position of the target, add the velocity*time vector, and that’s the position you should aim at.
You can either hard-code the travel time (half a second, or whatever,) or you can in turn measure the distance between AI and player, and divide by bullet travel time, to come up with an approximate travel time.
You can also apply a differential equation to calculate the exact time of impact and exact direction, but that requires a little more math and is slightly harder to write out, so I think the above will work best for you.
Thank you very kindly jwatte!
I am sorry that it took me this long to reply, but I had put everything with Unreal on the shelf for a while, and I just now came back to this issue and tried your suggestion. It took me a good while to figure it out, but it works in the end. I am quite scared of my enemies now lol
The only issue I am having is that I have to hardcode the bullet speed, because I just can’t seem to figure out how to cast to my projectiles properly. Darn object is always confusing me
That is exactly what the math is doing. It’s calculating the position to aim at. If the target doesn’t move, the position to aim at doesn’t move.
If you want to calculate “in what direction to aim” then you need to plug the target aim location into something like LookAt to figure out the orientation. Or just calculate TargetPosition - SourcePosition to get a vector.