Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Sparky's collision slowing down my pathfinding code

Author
Message
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 27th Jun 2013 03:18 Edited at: 27th Jun 2013 03:20
I've been working on some simple AI for the last few days, it's supposed to be for zombies. Basically, the object always moves towards the player unless a ray cast between the two is blocked by the map's walls, then the enemy moves towards a waypoint. These waypooints are are places where there are turns in the hallway. It runs at 45 FPS with five enemies without any sliding collision but under 35 FPS when I check collision for more than one enemy. I can include a full copy of the game if people want to run the code, but attached is the function I use for the pathfinding.

This is my first real attempt at waypoint pathfinding and good AI in general. Any feedback on my method would be cool too. I really want the game to have 20 or so of these zombies walking around at once, so performance is a must.

NOTE- the array ai_info(x,y) keeps information for each enemy (the first number of the array for each enemy, the second are listed below...

ai_info(1,0)- object number
ai_info(1,1)- active trigger
ai_info(1,2)- number for destination waypoint
ai_info(1,3)- reaction timer, so that the enemies don't reaction instantly to new player positions



BioFox Games
Daniel wright 2311
User Banned
Posted: 27th Jun 2013 04:11
Can I use this?

my signature keeps being erased by a mod So this is my new signature.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 27th Jun 2013 04:41
I mean if you really want to... like I said it's pretty slow when more than one entity is using the function. In fact, you could probably look at what I'm doing and do it more efficiently.

BioFox Games
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 27th Jun 2013 05:22
May I suggest that you call that pathfinding function (and many other routines) ~ 4 times a second, rather than every sync. Implement some tickers in your code that manage how often such things execute.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 27th Jun 2013 07:09 Edited at: 27th Jun 2013 07:21
Quote: "May I suggest that you call that pathfinding function (and many other routines) ~ 4 times a second, rather than every sync. Implement some tickers in your code that manage how often such things execute."

Exactly, cheat and cut corners in every way you can without there being noticeable and/or unacceptable loss in gameplay quality. All in the name of skipping as much workload as possible.

While skimping on measurements and processing is effective, so is simply being efficient. Cut your level into smaller sections and use Sparky's Collision Groups feature. You do some calculations to find out which groups need to be collision checked and work your way out from the closest. This way you eliminate collision checking most of the game world.

Don't run collision checking for anyone dead or standing still.


I'll also add:
You might also decide to really ramp up the zombie count into the hundreds or even thousands. If so you might consider disabling collisions entirely for zombies far enough away from the player, or in non visible sections of the game world if you have portal culling.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 27th Jun 2013 14:11
You can only walk to the next waypoint. If they are numerical then you can only walk from 61 to 62, or to 60. You can get location just from that. You can't collide with something at 59 or less, or 63 and higher.

By limiting what you can collide with, you can speed up the program many times over.

Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 27th Jun 2013 19:11 Edited at: 27th Jun 2013 19:12
Awesome, limiting the number of times the function is called works wonders! Thanks Burning Feet Man and Mage, I'll need to do the same for other functions in my game.

@Pincho Paxton, there is a limit on which waypoint the zombies can go to. It's the waypoint nearest to the player when the player no longer has a clear raycast between enemy and player. But I'll keep that in mind, the less collision I calculate the better.

BioFox Games
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 27th Jun 2013 19:55 Edited at: 27th Jun 2013 19:59
Quote: "@Pincho Paxton, there is a limit on which waypoint the zombies can go to. It's the waypoint nearest to the player when the player no longer has a clear raycast between enemy and player. But I'll keep that in mind, the less collision I calculate the better."


I don't mean limit the waypoints. If a zombie is near waypoint 60, and another is near waypoint 58, don't bother checking for their collision, they can't collide. Some people just check all collisions, all of the time. I store the nearest point instead, and only check neighbours. Collision loops can get huge very quickly otherwise.

Daniel wright 2311
User Banned
Posted: 27th Jun 2013 22:07
I would hide all objects, do not check for collision and also stop objects animations all together if you are not close to see the objects. this is real good advice for any one. I like the code other then that.

my signature keeps being erased by a mod So this is my new signature.
Bio Fox
21
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 28th Jun 2013 20:22
Ahh, I see what you mean. I'm gonna have to modify my code somewhat because simply slowing how many times the function is called always makes the enemies move in a jerky fashion. I need a system for checking distance between enemies and player so as to stop and hide all those not visible... thanks guys, hopefully in a few weeks I'll have something up in the WIP section with people bashing zombies.

BioFox Games

Login to post a reply

Server time is: 2026-07-06 18:35:51
Your offset time is: 2026-07-06 18:35:51