How can I make AI maintain distance to a moving object?

Just started using Construct 2? Post your questions here

Post » Thu Sep 04, 2014 1:40 pm

Hi,

I'm currently creating a top-down space exploration game, and am working on the AI side of things today. I've got AI enemies spawning from System -> Create Object and then moving to the player through fam_enemies_sml -> Set angle toward (player.X, player.Y), and moving via Simulate Car pressing Accelerate but this naturally moves the enemy to sit on top of the player object. How could I implement AI movement towards the player to within a certain distance at any angle?

Furthermore, how could I make the AI circle around the player? The only thing I can think of for the latter thus far is making four variables, being top, bottom, left and right around the player, then setting them to player.X or .Y minus distance variable, updating each tick and moving the AI to each in sequence? No idea how I'd pull that off though as of this moment.
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Thu Sep 04, 2014 1:45 pm

This sounds like a job for Rexraibow's LJpotential plugin :D
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Fri Sep 05, 2014 12:04 am

Hmm, I'll have a look into it, thanks, :). Might be back here with more questions, ha ha.
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Thu Sep 11, 2014 2:01 am

I would love to give you an answer, but sadly I have been looking for the same thing. :D any luck with the plugin?
B
10
S
2
Posts: 26
Reputation: 694

Post » Thu Sep 11, 2014 2:15 am

@martinDrew Haven't tried it yet, ha ha, lots of other areas to work on and the enemy AI functions decently enough for the time being, as you've seen, :). I'd also rather get by without additional plug-ins, so first I might try creating a transparent sprite near the player and directing aggressing ships to that, so they'll maintain distance but without need of a plug-in, :).
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Thu Sep 11, 2014 2:32 am

You could do it by just comparing the distance from the enemy to the player. Accelerate if the distance is greater than a radius and brake if less.

If you'd be happy with orbiting in a circle you could use the "move at angle" action on the enemy when they're closer than the radius and use enemy.angle-90 for the angle and say 100*dt for the distance.
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Thu Sep 11, 2014 2:38 am

@R0J0hound Cheers for that idea. I've done something similar using LOS to check if the enemy is in range and if so, to pull back a little so they're hit less, but wasn't sure how to check anywhere between the ships. I'll experiment with orbiting enemies as well, because I was hoping to introduce that a little later in AI development with a set of waypoints spawned around the player, which wasn't a very graceful idea.

Thanks! :)
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 5 guests