Aim AI: predictive aiming

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • This example shows how you can improve the way enemies aim at the player in your games. I made this because a lot of games use the "dumb" method, which is pretty rubbish. Here's an overview of the 3 layouts in this file:

    Layout 1: "Dumb aim": just always set angle towards player, and shoot regularly. By the time the bullet arrives, though, you'll have moved somewhere else, so it's easy to avoid fire. A lot of games do this, and you can just skip straight through heavy enemy fire by keeping moving!

    Layout 2: "Approximate aim": work out how long the bullet will take to arrive, then aim at where the player should be after that amount of time. Good, but not perfect - if the player moves further or closer away, the time of arrival changes, then the bullet misses. So some paths you run still mean enemy fire lags behind you. Not good enough!

    Layout 3: Perfect aim. Solves the equations to work out precisely where to aim the gun such that when the bullet arrives it intersects exactly with the player. If you run in a straight line, the enemy fire will hit you with 100% accuracy. The only way to avoid is to change speed or direction. Much more realistic and challenging! No more plain sailing through enemy ranks!

    The maths is provided in a comment in layout 3 and is pretty hardcore (I worked most of it out myself ) so you've been warned. I think I might make this a built-in expression or something, because it's very useful for gameplay and the formula is pretty complex.

  • Holy crap.. erm.. i mean .cap! amazing!

  • Awesome...enemy AI that hardly ever misses! Now enemy AI wont just kick my arse...it will completely own me!

  • btw Ashley a suggestion...instead of using global variables use private variables, because if u make a second turret it aims in the wrong direction. Although you could use the foreach condition loop...but private variables would be more efficient.

  • I think I might make this a built-in expression or something, because it's very useful for gameplay and the formula is pretty complex.

    Damn, I hope so I'm completely lost on the math.

    Works pretty flawlessly though. I'd say a mix of all three styles would probably be good for waves of grunts or enemy ships or whatever, but if they all had perfect aim that would make for a very frustrating game. Better for bosses and mini-bosses, or smaller groups of enemies.

  • you can still trick it though, by going back a little after every bullet is shot.

  • you can still trick it though, by going back a little after every bullet is shot.

    I thought that was kinda the point... that it's a system by which you have to be tricky to avoid getting hit.

  • you can still trick it though, by going back a little after every bullet is shot.

    Yep, only Foreseer can hit you or Instant Hit Bullet.

  • Yep. Now i want someone to program a forseer!

    btw. i'm working on a workaround for the perfect one. I know how to do it but i can't really get it right. I think i'll get it soon though. i'll upload it if i do.

  • Ok it still don't work, but have a look at this .cap, try to understand my thinking, and tell me if it's stupid.

  • Ok it still don't work, but have a look at this .cap, try to understand my thinking, and tell me if it's stupid.

    Very easy to dodge.

  • It's not supposed to work like it does. It's supposed to work like the perfect one. I realized that the code is very ugly, and i even use some objects that don't need to be there and so on. I'll post a new one that is commented and nicer. It still doesn't work like it should, but maybe someone can help me find the problem. Remember, this is just an IDEA! It doesn't work at all as it should.

  • Attan: You need to place the "Aim" in front of the player, not spawn it at their current XY.

    I did something similar once where I set it out in front of the player (distance) based on the speed the player was moving.

    So if the player moves right at a speed of 200, we can set the Aim about 100 Pixels to the right, from the XY of the player. The enemy will then be shooting ahead of the player, similar to what Ashley has with all the fancy math

    This method is fine for 8Dir and under, but 360 degress, I don't know.

  • Here's an updated example. The last layout uses 0.96.4's LinearAim expression, saving you all the math.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's quite useful!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)