Scripts / Flocking behaviour

Author
Message
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 26th Aug 2019 23:46 Edited at: 27th Aug 2019 19:31
i haven't experimented with flocking behaviour before so i figured i'd give it a go, this is what i get after the first attempt, works pretty well but actually works too well once they group up and get too far from other groups so they no longer swap around and makes it look too fake imo, i'll try add some randomness to it so they change direction after a while etc

script attached if anyone wants to play with it

@amen i know i remember you mentioned flocking before but i can't find any posts on it from you, if you want to jump in and add to the thread please do

edit; latest version of script added here too
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Aug 2019 00:06
A long time ago I did a herding script for sheep or cows. Used the concept of one member of the herd being the leader and the others following it but with randomisation so that each herd member behaved slightly differently.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Aug 2019 19:30 Edited at: 27th Aug 2019 19:34
new version;
- fixed the max speed so it actually adjusts how fast they move forward rather than just the rotation calculations
- added code to allow the boid to detect if it gets too far from its starting location and head back that way if so
edit;
fixed version with 60fps with 180 boids in map on highest - not sure how many i can add, this is just how many i had before

previous version for comparison (shouldn't be able to spot much difference)


there's probably some mistakes in there but i'm happy with the result, it is only intended for birds overhead or something of the sort so it doesn't need to be perfect anyway, some random behaviour is actually good in this case, though naturally a lot of boids do cause fps to drop, i shall see if i can reduce the drain next - done

first attempt at fixing the fps drain resulted in this circling behaviour... not sure why it happened but it's cool
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Aug 2019 21:13


Did that back in 2016! Still works as well which amazed me given all the changes to GG since then.
Been there, done that, got all the T-Shirts!
PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 27th Aug 2019 21:36
Nice floking smallg.

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 27th Aug 2019 21:59
So you magically revived the California Condor population significantly!

Neato, it's pretty good.

I wonder how (what pattern if any) these where place in the map- or random?
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 27th Aug 2019 22:39
yh i knew i remembered seeing it from you before but search found nothing

for mine i just placed them randomly using the spray tool mostly then raised them up in groups (as the spray tool defaults to the terrain, that's also why some are flying up or down a bit as the spray tool has some small random z rotation).
flocking code is designed to cause the boids/entities to group together naturally so as long as they get near each other during flight they will automatically form patterns, for my tests i have the group range check quite low which is why they form smaller groups but you can adjust it to pull in from larger radius for forming larger groups

i think the random circling was due to the secret fibonacci sequence that is part of flocking but i have no idea why it triggered like that, i didn't change the numbers, just made the script not update so frequently...
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 28th Aug 2019 05:10
Wow! Great stuff.
RIP
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit, Screen resolution 1680 x 1050.

New:
Intel(R) Core(TM) i5-8400 CPU @ 2.81GHz, 12GB RAM, Nvidia gtx1050ti 4gb, Windows 10 Home 64bit, Screen resolution 1920 x 1080. System Passmark 3774




Solar
7
Years of Service
User Offline
Joined: 11th Apr 2017
Location: South Africa
Posted: 28th Aug 2019 07:59
Haha! Wow! This is so cool!
PM
SOLO DESIGN
16
Years of Service
User Offline
Joined: 30th Jul 2008
Location: Kent, England
Posted: 28th Aug 2019 09:54
Hi smallg,

This looks cool, can you do something say working with Bats flying out of a cave and circling around before moving off???

Great coding though!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 28th Aug 2019 10:03
Quote: "This looks cool, can you do something say working with Bats flying out of a cave and circling around before moving off?"

probably more of a predetermined pathing system but you can add points of interest to the flocking system, it's how they return to their start location so you could input the mouth of the cave as the desired target position along with a variable to check if they already reached it or not, then allow the rest of the code to continue afterwards
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-12-22 09:13:13
Your offset time is: 2024-12-22 09:13:13