Cant Make AI Chase Player!

Discussion and feedback on Construct 2

Post » Wed May 18, 2016 3:26 am

Hello there,

I have an issue that i need fixed. I'm making a game that i think would be really cool but i cant execute it! I'm fairly new to Construct 2 and I just bought it so I know pretty much nothing . So I need to make the AI or Enemy chase the player when in range ( Ive already made it turn towards the angle of the player but the LOS is indeed broken.... So I cant figure out why the AI wont go after the player? Any help would be nice!

Thanks in return AfterLifeGames! :D
B
15
S
5
G
2
Posts: 31
Reputation: 2,002

Post » Wed May 18, 2016 7:56 am

Giving some more info about how your game works, or even better, posting a capx file that includes the part that you want us to help you with, could be very useful to the rest of us, in order to help you.
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Wed May 18, 2016 6:26 pm

eli0s wrote:Giving some more info about how your game works, or even better, posting a capx file that includes the part that you want us to help you with, could be very useful to the rest of us, in order to help you.



So I figured out how to make the AI chase the player but the AI wont wander aimlessly around the map! Also no matter where i am in the layout it will find me is there anyway that i can make it to where only a certain distance or if i can only be seen where the AI is looking?

and i dont know how to post CAPX file on here.... :3
B
15
S
5
G
2
Posts: 31
Reputation: 2,002

Post » Wed May 18, 2016 9:07 pm

You can host your capx file on a site like zippyshare or dropbox , then post link here. Also how is your friend the Fa$$ot when you were looking for his boner?
Check out my awesome Android Game releases https://play.google.com/store/apps/deve ... ames&hl=en
B
38
S
18
G
24
Posts: 681
Reputation: 16,613

Post » Wed May 18, 2016 9:10 pm

LOS sometimes has its own mind or breaks.... instead of LOS you can use the system expression compare two variables and calculate the distance as this :

distance(ai.x,ai.y,target.x,target.y)<100 ---->actionfor AI sprite{set angle towards position (target.x,target.y) } / action2 for AI sprite{ moveforward 2px+(60*dt)............}

the 100 acts as the visibility... however this has no view cone as los has its automatically 360 view.. so even if you come from behind it... will still follow the player.
B
70
S
20
G
67
Posts: 1,314
Reputation: 42,301

Post » Wed May 18, 2016 10:08 pm

gamecorpstudio wrote:LOS sometimes has its own mind or breaks.... instead of LOS you can use the system expression compare two variables and calculate the distance as this :

distance(ai.x,ai.y,target.x,target.y)<100 ---->actionfor AI sprite{set angle towards position (target.x,target.y) } / action2 for AI sprite{ moveforward 2px+(60*dt)............}

the 100 acts as the visibility... however this has no view cone as los has its automatically 360 view.. so even if you come from behind it... will still follow the player.



So essentially I cant make it where the enemies view is the only way i can be found and i was thinking of making it where i could backstab the enemy sneakily and that would be the only to kill them
B
15
S
5
G
2
Posts: 31
Reputation: 2,002

Post » Thu May 19, 2016 4:15 am

AfterLifeGames wrote:So essentially I cant make it where the enemies view is the only way i can be found and i was thinking of making it where i could backstab the enemy sneakily and that would be the only to kill them


You could have an AND event added to visibility that checks player position relative to AI position, rotation would affect where the player is "unseen".
B
7
S
1
G
2
Posts: 16
Reputation: 1,392

Post » Thu May 19, 2016 7:22 am

AfterLifeGames wrote:So essentially I cant make it where the enemies view is the only way i can be found and i was thinking of making it where i could backstab the enemy sneakily and that would be the only to kill them


well you can, you basically can reproduce the LOS behavior by event sheet, the code i gave as a example is only measuring the distance to trigger the follow action.
For "visibility" or cone view effect, you need to calculate the direction the AI is facing... however it might be you are using LOS wrong and thats why it breaks. take a look at the RTS example in the default templates of C2 that might help you understand better the LOS usage.
B
70
S
20
G
67
Posts: 1,314
Reputation: 42,301

Post » Thu May 19, 2016 7:55 am

You could use Turret behaviour combined with LOS.

The LOS looks if the player can be seen, accounting for obstacles. Not seen = dissable the turret.

The turret takes care of the angle (only rotates when the player is in range), take care of choosing the moment that it will run to the player (when it has a target), knows at wich angle to move towards the player.

Or LOS combined with Pahfinding.

Attach a invisible object to the nose of the player. Give it a high Cost. Now the Pathfinder wil prefer the back of the player for aproaching.
B
33
S
18
G
27
Posts: 2,441
Reputation: 20,346

Post » Thu May 19, 2016 11:24 am

Here is a basic solution using the pathfinder plugin, in combination with the Line of sight plugin. I haven't implemented any backstabbing logic, but the enemies try to follow you if they have a direct line of sight and you are within their viewing distance.
https://www.dropbox.com/s/5fnknrr5b79svra/AI.capx?dl=0
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Next

Return to Construct 2 General

Who is online

Users browsing this forum: tumira and 1 guest