Fish

Started by
20 comments, last by aboeing 20 years, 7 months ago
Hi, I am trying to implement a schooling fish behaviour, and have applied some of the concepts from boids, but my fish act very much like birds. (Specifically they either follow the "destination" point in a V-formation, or, if I change the parameters enough they will form a sphere around the destination - neither is how fish move) So can anyone tell me either whats wrong with my code, or what parameters / extra influences I need on the fish. Cheers.

void CalcDir(Boid *b, int me, int nBoid) {
		Vector3 heading;
		heading = dest-pos;
		heading.Normalize();
//		dir=heading;	

		float ndiv;
		ndiv=0;
		Vector3 seperation;
		Vector3 alignment;
		seperation=Vector3(0,0,0);
		alignment=Vector3(0,0,0);
		Vector3 centerpos=pos;
		for (int i=0;i<nBoid;i++) {
                  if (i==me) continue;
			Vector3 dist;
			dist=pos-b[i].pos;
			float md;
			md=dist.Mag();
			float tsize=percieved_size+b[i].size;
			if (md<tsize) {
				centerpos+=b[i].pos;
				float severity=(tsize-md)/tsize; //0..1

				severity*=2;
				severity*=severity;
				seperation+=(dist*severity);
				ndiv++;
				alignment+=b[i].dir;
			}
		}
		if (percieved_size>size) {
			percieved_size/=1.1f;
		}
		if (percieved_size<size) {
			percieved_size=size;
		}
		centerpos=centerpos/ndiv;
		Vector3 cohesion;
		cohesion = centerpos-pos;	
		cohesion.Normalize();
		seperation.Normalize();
		alignment.Normalize();
		//changing the parameters below changes the 'behaviour' of the fish.

		dir=(heading*1.0f)+(seperation*0.3f)+(alignment*0.2f)+(cohesion*0.8f);
		dir.Normalize();
		dacl=dir; //set the direction of the acceleartion of the fish

	}
[edited by - aboeing on August 8, 2003 10:52:10 AM]
Advertisement
Ehm... I''m not a moderator, but this should have gone into the AI forum, not the graphics forum. The guys there will be able to help you more... Nevertheless, it''s better if you don''t start another thread there yourself (double-posting is not encouraged here...), but rather wait till one of the moderators moves this thread there.

I''m not very fluent with flocking algorithms, so unfortunately I can''t help you much more than that. Although I think that to get the type of behavior you are looking for, you need your algorithm to do the following few things (this is just my best guess though, I may be way off):
1. Set the direction of school''s movement to dist-pos. This could perhaps be done by setting the approximate direction of each fish to that vector.
2. As your school moves, make each fish try to immitate the movements of the few nearest fishes (i.e. make it attempt to move in approximately the same direction and speed). But you need to be careful to make sure this doesn''t prevent the school from taking turns and such.
3. Once the school reaches its destination, select a random new destination in the vicsinity of that one, to make sure the school always keeps moving.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"


We come in peace... surrender or die!
Michael K.
quote:Original post by technobot
Ehm... I''m not a moderator, but this should have gone into the AI forum, not the graphics forum. The guys there will be able to help you more...

Yep, that''s right. Moved.
hey,
yeah sorry guys, i wasnt too sure about which forum it should go to.. animating fish/birds always seemed more of a graphics topic than an AI topic to me..
anywho,
wrt 1) - i figure thats what giving every fish a bit of the ''heading'' would do..
2) this is what i figured the cohesion (move towards neerest fishies) and alignment (move in same dir as fishies) does,.. the speed is normalized in the end, so they always move at the same speed, regardless.. (is this a/the problem?)
3) - good idea!

I have tried assigning most of the fish 1.0 cohesion & 0.3 seperation, and then just giving the rest a standard behaviour, so i figured this would result in a few "leader" fish, and a whole bunch of "follower" fish, and this has made the school a bit more spread out, but they still dont look good.. fish in real life seem to be darting about and move out in little ''streams'' and have a more ''cylindrical'' (for the lack of a better word) structure..
quote:Original post by aboeing
animating fish/birds always seemed more of a graphics topic than an AI topic to me..

Drawing them on the screen is a graphics topic. Deciding where they should go is AI.



Dave Mark - President and Lead Designer
Intrinsic Algorithm - "Reducing the world to mathematical equations!"

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Is this the sort of behavior you are looking for? (this shows a 'shoal' of agents evading a large passive wandering agent)

http://www.ai-junkie.com/files/Big_Shoal.zip


PS. flocks/shoals do not have leaders and they do not need a 'destination point'


My Website: ai-junkie.com | My Book: AI Techniques for Game Programming

[edited by - fup on August 8, 2003 3:04:03 PM]
boeing,

Regarding suggestion 3 by technobot, rather than choosing a new destination at random perhaps you could implement the wandering behaviour illustrated by Craig Reynolds. (This goes back to a previous discussion we''ve had in which I suggested checking out his site. Did it prove useful?) By wandering the center of your sphere you may get the group movement your seeking.

As for single fish darting in and out, perhaps this could be accomplished by randomly influencing a fish to move away from the school''s center. This would get the rolling effect you often see in large schools of oceanic fish.

fup - nice demo. You always have good ones!
fup: The demo didnt run on my machine =(
[winxp sp1, athlon1800+, dx8.1, leadteck a250 geforce 4 ti]
kirkd: I sent you an email, hope u dont mind, also, the boids model craig reynolds suggests is quite similar to what i have, (in fact identical, which makes me think the info i got was from someone who got the info from him..), except he doesnt have a global heading at all... [when i remove this, the fish just move around randomly, and if they do form groups, they eventually "explode"]

I have tried increasing the seperation rating, as you suggested and this just makes the fish more ''independent'' - but they do look less like birds, but fish dont really act very independently..

if anyone has any other small demo programs or source i would really love to take a look
fup: The demo didnt run on my machine =(

That is most odd indeed. The demo uses the GDI in order to avoid any potential hastle you can get with DX, OpenGL etc. What happens when you try and run it? Did you make sure you extracted the files to their own folder before you clicked on the executable? (the exe needs the ini file to run)

All: Has anyone else experienced this problem?

When I ran the demo it just said this:
Steering.exe has encountered a problem and needs to close.
We are sorry for the inconvenience.
I am running XP and DX8.1 too, the problem could be related to one of those. I did make sure the ini was in the same dir. What is GDI anyway?

[edited by - WhtRbt on August 9, 2003 4:39:34 AM]
- Go not to the elves for counsel, for they will say both yes and no.

This topic is closed to new replies.

Advertisement