Aim AI: predictive aiming

Post your own tutorials, guides and demos.

Post » Fri Aug 01, 2008 11:42 pm

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 8) ) 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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,590

Post » Fri Aug 01, 2008 11:52 pm

Holy crap.. erm.. i mean .cap! amazing!
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Sat Aug 02, 2008 2:15 am

Awesome...enemy AI that hardly ever misses! Now enemy AI wont just kick my arse...it will completely own me!
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Sat Aug 02, 2008 2:19 am

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.
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Sat Aug 02, 2008 10:09 pm

[quote="Ashley":1qj07o1w]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.[/quote:1qj07o1w]

Damn, I hope so :shock: 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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Aug 02, 2008 10:12 pm

you can still trick it though, by going back a little after every bullet is shot.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Sat Aug 02, 2008 10:24 pm

[quote="Attan":2hx7hjkr]you can still trick it though, by going back a little after every bullet is shot.[/quote:2hx7hjkr]

I thought that was kinda the point... that it's a system by which you have to be tricky to avoid getting hit.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Aug 02, 2008 10:34 pm

[quote="Attan":1w9viye1]you can still trick it though, by going back a little after every bullet is shot.[/quote:1w9viye1]
Yep, only Foreseer can hit you or Instant Hit Bullet.
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

Post » Sat Aug 02, 2008 10:55 pm

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.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Sat Aug 02, 2008 11:19 pm

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.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests