Scripts / Fish shoal script

Author
Message
Gtox
3D Media Maker
10
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 29th Jan 2017 14:29 Edited at: 16th May 2019 21:03
I saw an excellent tutorial for shoaling/flocking behaviour for Unity, which I used to pretty good effect. I decided to have a go at adapting it for LUA/GameGuru, but found it tough going (my programming skills are not good enough). The end result is a bit of a hack job, but it works pretty well. The behaviour is not as organic as the Unity version (the use of Quaternions, as well as a few other tricks, in the C# script may have a bit to do with it), but there's enough randomization in the LUA version to give a rough approximation of what the C# version was able to do.
To get it to work in GameGuru, you'll need a model with ischaracter set to 0 (if your model has icharacter set to 1, you need to set fixnewy to 180 otherwise it'll move backwards), physics set to 0, anim0 must be the swim animation and playanimineditor set to 1(the scripts don't deal with animation at all).
One fish acts as the leader (use flock.lua), all the rest use flock_follower.lua. You'll need to get the entity number of the leader (hover the mouse over it in the editor and get the number from the bottom of the screen) and change 'leader=2' in the init section of the flock_follower script to whatever your leader's entity number is.
The range is set in the init section of the flock.lua script. By default it's 500, so you can adjust it to match the size of your water body.
The pool should be fairly deep, otherwise they will clump together and there is a greater chance of them passing though each other. They will also pass through other objects and the terrain (they are scripted to stay at least 10 units above the terrain, but if the banks are steep they'll pass through it).
At the start of the flock_main section, there is a bit of code to stop you from dying when underwater - you can remove it or comment it out as needed.

If anyone wants to have a crack at recreating the original scripts (or improving mine), be my guest - the link to the tutorial video is below (I won't embed the videos). If you have a very good understanding of LUA, you won't need to understand the C# scripts - the tutorial explains the basic rules of flocking behaviour very well, so you should be able to translate the behaviour into LUA.

Tutorial - https://www.youtube.com/watch?v=eMpI1eCsIyM
Unity version - https://www.youtube.com/watch?v=vaT1w3EPbiI
GameGuru version - https://www.youtube.com/watch?v=6PaKNdr602c

In theory this could be adapted for birds, but there would be some script-fiddling required.

As usual, I've used some of smallg's extremely useful functions in these scripts, so thanks for that.
i3 8350k 3GB GTX1060 8GB RAM Windows 10

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 29th Jan 2017 20:04
Here you go, this might help.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 29th Jan 2017 21:17
This reminds me of the herding script I wrote last year, these are for sheep and use the AI system so they are a lot simpler.
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 29th Jan 2017 23:46
Lol, I watched the tutorial you linked to, "the first flocking .. etc.. was used in the Lion King", really? I remember writing flocking routines way before the Lion King came out, actually the first I can recall was in 1982 for a spectrum game I was working on.
Been there, done that, got all the T-Shirts!
PM
Gtox
3D Media Maker
10
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 30th Jan 2017 04:28
What Spectrum game were you working on, a commercial game or a private project?
ps that Quaternion info is Greek to me, I should put my reluctant brain to use and do a bit of research.
Gtox
3D Media Maker
10
Years of Service
User Offline
Joined: 5th Jun 2014
Location: South Africa
Posted: 30th Jan 2017 05:04
Looked up quaternions on Wikipedia - my brain hurts.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Jan 2017 10:56
Luckily you don't need to understand them to use them.

Don't know if the game went commercial, the code was actually developed on a PET in 82, one of the guys in the computer club had one which automatically made him club leader.

In early 83 I moved away so I don't know if they ever got as far as a commercial release, don't even think we had a name for the game when I left, was space based and the idea was to have swarms of aliens attacking but if you hit the leader (there was nothing to indicate the leader visually you had to work it out from the behaviour) the the swarm would break up and attack individually which made them easier to take out. Sort of Galaxians on steroids, the player was manning gun turrets on a space ship and had to knock out waves of aliens as the ship gradually got destroyed around you. If you made it through so many waves the ship was repaired and you started again on the next level, there was a story around it IIRC, something about smuggling runs or similar.

Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-23 03:46:23
Your offset time is: 2024-12-23 03:46:23