• News

• Industries

• Learning & Support

• Community

• Marketplace

# How to make a flying enemy accurately bomb the player.

Hello all!

I’m working on a 2D side-scroller type game for mobile. At this moment, I have a flying enemy character with a droppable bomb-type actor attached. My goal is to set up a targeting system to make my enemy character drop the bomb so that if the player character is either standing still or maintains its movement at the current speed/direction, the bomb will pretty much bullseye the player character (small margin of error is the goal, but some slop is fine for playability reasons).

I haven’t yet started scripting the release timing, but my current idea revolves around using 2 box collision components attached to the flying character to act as triggers, whose position forward of the flying character is scaled by the forward velocity of the parent flying character. The further trigger would either trigger a drop event right away or a delay (depending on player character direction, speed, is moving status) and the second would be essentially the same. I can’t help but feel like there’s a much nicer/cleaner way to implement this kind of targeting, but I’m still learning and haven’t been able to find tutorials for this sort of thing.

Also, my bomb is a simple physics object that upon release has physics simulation, gravity, and collision enabled and is then given a small impulse based on the dropping character’s forward velocity. It has no movement component of its own, as it’s intended to be just a falling object.

I posted this in the AnswerHub, just putting it up here for more visibility.

Thoughts, anyone? Am I on the right track here?

make bomb or bomber a blueprint.
In that blueprint get actor own location and velocity, then find player actor, get its location and velocity.
Then google about newton mechanic, get formula for free fall. Add that relative speed of player and bomber. Formula should be about as hard as elementary school gets. Find when to release bomb. Add some margin for errors ie. do not release only whne formula is meet but at margin of +/- 2% or so.

That is most clean solution.

you want a homing bomb? you can set this up in projectile movement component. just add it to your bomb

Majek, I know what you mean, but I’m really looking for the bomb to be a free-falling object. Just need to be able to predict where it’ll land in order to trigger the drop timing properly. That said, it looks like Nawrot is thinking the same thing I was, essentially. Did some digging and found a resource that has listings of all sorts of trajectory/ballistics equations.

http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html#tra4

If you look under the “Horizontal Launch” section, they have a Range equation that looks to be exactly what I need in order to set this up. I’ll just have to figure out how far to space the trigger in front of the estimated landing to time the drop right.

I will update as soon as I get a chance to implement this and let you know how it goes. In any case, thanks much for the help, folks!

I was able to set up a custom function that runs the horizontal launch range calculation and that seems to have gotten me the relevant target point (or very close, as I’m using an impulse to carry the momentum of the bomb dropper enemy). With a bit of tuning to compensate for the impulse vs actual velocity at launch (easy error margin tuning right there), I’ve got it so that if you are running toward the dropping enemy or standing still, he’ll pretty well hit you right on the noggin (just adjusted my initial velocity input down by 15%). Now, I’ll just need to tune for when you’re running away from the dropping character and figure out how to factor in wind layers and I’m golden! Thank you!