x, y but no z please

hey,

i want to have a kind of 2-d flocking beahviour but in a 3-d world...
so the agents will stick to the same 'altitude' as it were.
any idea's on starting the agents off at the same level and keeping them there?

cheers
t

x, y but no z please

breve doesn't explicitly support 2D worlds, but the following hack at the bottom of an agent's iterate method is surprisingly effective:

  location = (self get-location).
  location::z = 0.
  self move to location.

- jon

x, y but no z please

hi

i get an error using that code:

object type "Swarm" does not respond to method "get-location" with 0 keywords

	+ to iterate:
		location (vector).
		topDiff (double).
 
		self update-neighbors.

		# get the average location, and point the camera at it.

		foreach item in birds: {
			item fly.
			location += (item get-location).
		}

		# in the context of a number, the list represents the number of items 
		# in the list.

		location /= birds.
		# print "the highest location is $location".

		topDiff = 0.0.

		foreach item in birds: {
			if topDiff < |location - (item get-location) |:
				topDiff = | location - (item get-location) |.
		}

		# we'll try to keep the camera aimed at the center of the 
		# flock, and zoom in and out depending on how spread out the 
		# flock is.  it's doesn't work very well :).

		self aim-camera at location.
		self zoom-camera to (.5 * topDiff) + 10.

                
                location = (self get-location). 
                location::z = 0. 
                self move to location.

		# call the superclass iterate method to step the simulation forward.

		super iterate.

help!?
t

x, y but no z please

You should add those three lines of code in the iterate: method of the agent's class (Bird), not in the control class (Swarm).

x, y but no z please

jk wrote:breve doesn't explicitly support 2D worlds, but the following hack at the bottom of an agent's iterate method is surprisingly effective:

  location = (self get-location).
  location::z = 0.
  self move to location.

do i need to define a new variable location and will it be a vector or array or matrix or????

help!?
thanks
t

x, y but no z please

Yes, declare a vector variable location.

- jon

x, y but no z please

sweet it works... well it's put them in a fix x/y axis but i can tweek that...

2D

i got same error. in which part i should define the variable location and how to define the variable.

thanks
L

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.