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 / Field effect pathfinding

Author
Message
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 19th Nov 2006 11:41 Edited at: 15th Feb 2007 21:44
<Updated; summarised to save you having to read down the thread.>

Field effect is an AI pathfinding solution for complex envornments where waypoints will not suffice. it's a way of making AI avoid or be attracted to each other, while avoiding obsticles.

Basically the code works by replicating the universal gravity laws (hence the name field effect, from gravitation fields):

attraction (force in newtons) = -([mass of object 1] * [mass of object 2] * [universal gravity constant]) / ([distance form the two centres]^2)

or: -GMm/r^2, minus being because it is an attractive force

We can modify this slightly. Replace G with an attraction constant. this is how much the ai will be attracted to each other in general.

Now instead of making this a fight between the fattest, I changed the mass to the specific desire for that NPC to take out other NPCs, and then the second mass with the "ugliness", of the second NPC. we'll use r^2 in the same way.

here's the code I came up with, and below is a link to the project I'm using it with. I may write a proper tutorial on this at some point.



http://forum.thegamecreators.com/?m=forum_view&t=93666&b=32&p=0
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Nov 2006 21:16
If the phrase 'Field effect pathfinding' returns nothing on Google, then is it safe to assume this is a phrase you have made up yourself? If so, what exactly do you mean?

El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 19th Nov 2006 22:55
well its the term i was told in the IRC channel <insert promo for the darkbasic irc channel here>

anyway, its basically where every obsticle has a repulsive field, just like an electric field or magnetic field, repelling the ai, but having an attractive field located at the ai's target, thus with vectors, it is seen to travel smoothly around the object

or that's the theory.
lower logic
17
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 20th Nov 2006 01:00 Edited at: 20th Nov 2006 01:07
I didnt have much to do so I just wipped up this bit of code that I think does what you're saying:
Left click to attrach units to the mouse, right click to repell them from the mouse. Units and obstables repell and units repell each other. When not clicking the units wander around based on the forces of the obstacles.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 20th Nov 2006 02:53
i have no idea where to find a tutorial for this kind of thing, but just have a go. I would suggest precalculating an underlying potential for unmoving objects, and adding contributions due to the stuff that moves around at runtime.


You'll be able to click on this someday.
flibX0r
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Western Australia
Posted: 20th Nov 2006 03:07
Only thing I could find about it:
http://www.gamedev.net/reference/articles/article1125.asp

Big whorls have little whorls which feed on their velocity,
Little whorls have lesser whorls and so on to viscosity. - Lewis F. Richardson
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 20th Nov 2006 17:58 Edited at: 21st Nov 2006 14:03
wow - lower logic, i wasnt excpecting code but that looks awesome.

in school today i decided to use the formula: d=-(WA)/r^2

d is the desirability to go in the direction of:
W, the willingness of the npc to avoid objects (ie ghosts dont need to, and objects with shallower turning circles ie a high speed horse, needs more room around it,
multiplied by A, the importance of avoiding the obsticle in question, for example it's more important to avoid fire then just a muddy patch on the ground
divded by the radius beteween the npc and obsticle squared, giving a fallout effect.

the npc's target would need to have a negative A so that it actually attracts the npc to that direction.

ps, flibble, is that you?

edit: my idea completely failed. i tried anotating your code, could understand about 95% of it, tried using what i could understand to code my own system from scratch, failed again.

i have however modified your code to supoort 3d.



hopefully you dont mind me using this code. i just need to go through and optimise it, and also add the ability to attempt to dodge bullets.
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 1st Dec 2006 10:55
update: (sorry to bring up an old thread)

while the code works for small ammounts of AI, i found that it doesnt work well with.. large amounts (surprisingly)

this weekend i'll be modifying the code to work with vectors, and then i'll post the code, just thought some people who might have used the code, or for anyone who in the future will find this thread looking for teh relevantz codez, would benefit, tis all ^_^
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 1st Dec 2006 12:33 Edited at: 1st Dec 2006 12:39
El Goorf, check out this boids example I made with DarkScript, specifically the function "rule2" in the .gm file. The function uses vectors to avoid boids (but you can do it with other objects) that are too close. In the example I put the sync rate at 60, but you can see how good the algo still works with more than 100 boids going at once (by changing the value in the script).

[edit]
A simplier pseudocode for avoidance with vectors looks like this:


El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 3rd Dec 2006 12:34 Edited at: 3rd Dec 2006 15:31
after spending 2 dys learning how to use vectors, here's what i came up with:

EDIT: fixed code below:



however, the sphere still goes wierd. you have to go to line 64 and change it to (for example)

move object 2,1

i'd like it to be working timer based but its not happenin for me >.>
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 3rd Dec 2006 18:22 Edited at: 3rd Dec 2006 18:31
Froog, hope this helps:



[EDIT] Modified code as we spoke of in #db. basically, ensure initialisation of variables, but time2 just needed initializing

Paul.

El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 3rd Dec 2006 22:34
ok, thanks to the help from apex, i now have code for making the npc's avoid each other or attract towards each other.



just one problem though. once they all sort themselves out and get equally spaced etc, why do they then all shoot north?
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 3rd Dec 2006 23:03
hm... this is an interesting object-avoidance theory. ive never seen it before, but it sounds like it would work really well, while saving the FPS.


forum.thegamecreators.com/?m=forum_view&t=78971&b=8&p=0
forum.thegamecreators.com/?m=forum_view&t=91115&b=32
El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 3rd Dec 2006 23:35
and here we have the code with targets+NPC, which i spent since the time i ade the last post putting together:



what i'm going to do now is make it so that the ai will only be attracted to its nearest target, and then i will upload the code, ad then if i ever have a free moment, i'm going to tidy up this thread, put all the relevant stuff into the first post and summaries it so new comers to the thread dont have to deal ith our random mumbling

but giving away any mroe code than that would be giving away code used in my nvidea compo entry so thats it from me ^_^
DrDunc
18
Years of Service
User Offline
Joined: 2nd Nov 2005
Location: MemBlock 12 (alt. file Thinking12.mem)
Posted: 4th Dec 2006 00:45
Thats sooo cool!
Lots of potential there!
Torrey
19
Years of Service
User Offline
Joined: 20th Aug 2004
Location: New Jersey
Posted: 4th Dec 2006 03:52
That was nicely done! The complexity of AI can confuse lots of people, but the way you kept it powerful while being simple is excellent. One thing I thought about today while doing some research on AI was, what is the speed impact on games developed with dbpro when it comes to using AI like this? Right now I'm thinking that single player games would work fine using methods like these, but multiplayer games would be brought down to such a slow speed because of all the computation. Is this thought right?

El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 4th Dec 2006 11:20 Edited at: 4th Dec 2006 19:42
this is it, the final code snippet, everything working, the npc's now find the nearest target and head towards it.



if you find any problems ie ai walking into each other or trees instead of avoiding them, try changing
1) the force
2) the distance in which the force takes effect

also, to change whether the ai is attracted or reppeled to/from an object, change the force from positive to negative, or vise versa

edit; now, if anyone could give me any ideas as to how i can make swerving type movement, to give the effect of say, evil floaty spirits gliding through the woods smoothly, please give
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 4th Dec 2006 21:31
That is one awesome techinique. I think I will steal that from you

El Goorf
17
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 5th Dec 2006 23:51
here we go, to see field effect in action:

http://forum.thegamecreators.com/?m=forum_view&t=93666&b=32&p=0

for my competition entry, where you can find a downloadable demo exe.
Steve J
18
Years of Service
User Offline
Joined: 22nd Apr 2006
Location: Vancouver, Washington
Posted: 6th Dec 2006 03:05
That is seriously an excellent idea. That would work perfect in a space game (avoid other ships, asteriods, planets, stars, ect), while if nearing a black hole it would attract the ship=). Great idea, I am going to experiment with it.

http://phoenixophelia.com

Steve J, less, and less Controversial!

Login to post a reply

Server time is: 2024-05-04 18:47:11
Your offset time is: 2024-05-04 18:47:11