# How to let enemies calculate trajectory with projectiles?

Godot Version 4.1.3

I’m making a 3d first person shooter, and I’ve given the enemies projectiles, but they aren’t accounting for gravity when they shoot, so they’re always shooting too low, how can I let them account for gravity when they shoot?

1 Like

That’s part of the “AI learning algorithm.” They shoot, they miss their target, then they try to compensate with the coefficient of difficulty like wind, gravity or other variables.

In short, enemies shoot for spot X. You provide them by how much they missed. They adjust. Difficulty might be variable making things even more difficult.

Then there’s the “if it hits, it hits” and that’s it way of doing things. That’s all up to you.

There is no perfect way, only the best way for your concept.

1 Like

I think it should be something like this:

``````angle = (1/2*sin^-1((gravity*distance)/projetilesvelocity^2)
``````

this account for the distance of the player but not there movement
@aurora-veill
and only the upward angle, idk what happen if it exceeds the maximum distance

1 Like