AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Entity chase player without stuck (https://forums.alliedmods.net/showthread.php?t=324905)

Celena Luna 05-31-2020 11:47

Entity chase player without stuck
 
I am writing an Zombie Entity that would chase player when they when close.
But the map have a lot of obstacles that player can abuse and make the Zombie stuck on the other side (like a table or a car) and kill it easily

I was thinking about using A* Pathfinding but it cost a lot of CPU

Another method I was think of is mark player's origin every 10 distance => Make Zombie go to that origin in order

But it make the Zombie look stupid if player just running around a circle and then the Zombie did the same.

Is there other method/way I could use for this problem?

Xalus 05-31-2020 13:44

Re: Entity chase player without stuck
 
1 Attachment(s)
I've try'd to make such Zombie AI in the past,
I'll add the code, see if there is anything usefull in it.

NOTE: Only a few functions work, A* Pathfinding is broken to last time I tested it.
Also code is old, optimizes recommended.

Natsheh 05-31-2020 20:10

Re: Entity chase player without stuck
 
i'd suggest to make a predefined path origins for the map.

as czbots work

You do still need efficient path finder to help you with the obstacle and setting the path origins

DJEarthQuake 05-31-2020 20:42

Re: Entity chase player without stuck
 
Make touch so zombies can pass through the 'obstacles'.

Xalus 06-01-2020 02:38

Re: Entity chase player without stuck
 
Marking the player origin is an option,
if you add a check that bot could skip a few if possible & faster.

That would solve the circle problem.

Celena Luna 06-01-2020 08:42

Re: Entity chase player without stuck
 
Quote:

Originally Posted by Xalus (Post 2703341)
I've try'd to make such Zombie AI in the past,
I'll add the code, see if there is anything usefull in it.

NOTE: Only a few functions work, A* Pathfinding is broken to last time I tested it.
Also code is old, optimizes recommended.

I did something similar but the time to find and update the path was slower than entity's think so it usually move 1-2 second slower than the actual path. Also, it isn't detect as the boss size but player size so it seem broke. (I did saw the video on that plugin)

Quote:

Originally Posted by Natsheh (Post 2703399)
i'd suggest to make a predefined path origins for the map.

as czbots work

You do still need efficient path finder to help you with the obstacle and setting the path origins

is it like setting up origin then make the entity move to the origin in order to get to player? but isn't then every think, it have to loop all the predefined origin to check to see which origin is player close to and cost a lot of CPU?

Quote:

Originally Posted by DJEarthQuake (Post 2703400)
Make touch so zombies can pass through the 'obstacles'.

Oh, I really like a Zombie that can 1-shot walk though wall and slap me.
No, thank you.

Quote:

Originally Posted by Xalus (Post 2703429)
Marking the player origin is an option,
if you add a check that bot could skip a few if possible & faster.

That would solve the circle problem.

That what I planned at first but then how to I store it? if there is another Zombie Entity there, they update overlap each other if I using Array from ArrayCreate(). I need to clear the previous origin when reach so Stack like Array is needed.

Natsheh 06-02-2020 04:21

Re: Entity chase player without stuck
 
Yes celena it does consume alot of CPU but just for a while on the start of the map

CrazY. 06-02-2020 10:40

Re: Entity chase player without stuck
 
The only way I can think of is waypoints.
https://user-images.githubuserconten...54230fbcbb.png

The logic is quite simple, but will take some work.
1. You need to set the waypoints for each map and save the data, similar to map spawns editor.
2. In the zombie "walk function", check if there is any obstacle. If false, keep moving, if true, look for the waypoint closest to the zombie towards of its target and move it towards that point.
3. When there's no more obstacle or case the zombie has already walked to the waypoint, repeat from step 2
4. When the zombie reach its target, attack!

You can try to take a look at the artificial intelligence codes to see how it works like Podbots, HL1 source code or an open source game engine like Godot, and try to implement with amxx.

It's not impossible, it will just take some work. Good luck!

Celena Luna 06-04-2020 09:49

Re: Entity chase player without stuck
 
Quote:

Originally Posted by Natsheh (Post 2703617)
Yes celena it does consume alot of CPU but just for a while on the start of the map

Quote:

Originally Posted by CrazY. (Post 2703668)
The only way I can think of is waypoints.
https://user-images.githubuserconten...54230fbcbb.png

The logic is quite simple, but will take some work.
1. You need to set the waypoints for each map and save the data, similar to map spawns editor.
2. In the zombie "walk function", check if there is any obstacle. If false, keep moving, if true, look for the waypoint closest to the zombie towards of its target and move it towards that point.
3. When there's no more obstacle or case the zombie has already walked to the waypoint, repeat from step 2
4. When the zombie reach its target, attack!

You can try to take a look at the artificial intelligence codes to see how it works like Podbots, HL1 source code or an open source game engine like Godot, and try to implement with amxx.

It's not impossible, it will just take some work. Good luck!

Thank you. I will try and see if it work.
It is gonna be long :crab:

supertrio17 06-05-2020 02:08

Re: Entity chase player without stuck
 
Is there any way to "predict" the players path, or to use player path and randomize it a bit, so it wont look like that.

Natsheh 06-05-2020 03:17

Re: Entity chase player without stuck
 
its a bit odd check if a good path to go from point 1 to point 3 knowing the ability to skip point 2.

HamletEagle 06-06-2020 03:14

Re: Entity chase player without stuck
 
Guys, you can try to come up with all kinds of weird/hacky ways or fixes on top of fixes.
They will not work properly and you will end up with spagetti code.

The proper way is to implement a pathfinding algorithm like a* in a module. It can't be done in a plugin because the needed data structures are missing in pawn.

supertrio17 06-06-2020 14:08

Re: Entity chase player without stuck
 
Quote:

Originally Posted by HamletEagle (Post 2704254)
Guys, you can try to come up with all kinds of weird/hacky ways or fixes on top of fixes.
They will not work properly and you will end up with spagetti code.

The proper way is to implement a pathfinding algorithm like a* in a module. It can't be done in a plugin because the needed data structures are missing in pawn.

If that is true, then the best answer to this question is already answered, you must make checkpoints for every map you wish this plugin to work on.

HamletEagle 06-07-2020 03:07

Re: Entity chase player without stuck
 
Quote:

Originally Posted by supertrio17 (Post 2704319)
If that is true, then the best answer to this question is already answered, you must make checkpoints for every map you wish this plugin to work on.

This is not what I said. Waypoints are a possible solution but they require manual setup for every map.

DJEarthQuake 06-07-2020 04:25

Re: Entity chase player without stuck
 
One could also just alter the friction when they touch certain objects so they cannot get stuck and instead bounce off and hopefully keep going.

supertrio17 06-07-2020 09:00

Re: Entity chase player without stuck
 
Quote:

Originally Posted by DJEarthQuake (Post 2704402)
One could also just alter the friction when they touch certain objects so they cannot get stuck and instead bounce off and hopefully keep going.

Um, I'm not an expert, but wouldn't that make them look dumb. This thread was started because they looked dumb.

DJEarthQuake 06-07-2020 10:12

Re: Entity chase player without stuck
 
Quote:

Originally Posted by supertrio17 (Post 2704417)
Um, I'm not an expert, but wouldn't that make them look dumb. This thread was started because they looked dumb.

Monsters are supposed to have special edge handling. Friction is low cost on CPU.

Vieni 06-07-2020 10:50

Re: Entity chase player without stuck
 
I think you should check if the npc's slow, if it is, save it's angle, so we can use it in all the thinks.
After saving it, you should shoot like 5tracelines based on the npc's height(Flying stuff can block npcs either) and save the one, which's vector end position is near enough to block the npc. If there's no traceline like that, simply turn it around to look for someone else to catch(if there's no more enemies, I'd simply let him be there, or give them jumps[maybe the human is on a car or something]).

So, we have the height on which the npc's blocked, so we only gotta give some turning to our npc and check the traceline from the origin height calculation to the saved angle if the distance has increased enough to turn on the enemy. This still can be buggy, but much more less than now.

Oh, and i even would build something to it, what calculates if the player is on a heigher place than the npc, so you can give it jumps by it before the traceline stuff.


All times are GMT -4. The time now is 23:19.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.