Stick Page Forums Archive

AS2 Grouping

Started by: Sawc | Replies: 2 | Views: 401

Sawc
2

Posts: 908
Joined: Oct 2006
Rep: 10

View Profile
Jun 30, 2009 12:50 AM #450835
Alright guys, I'm working on a game using as2 (ya, I should be using as3, so what?). Let's say you have a group of ai fish or planes or something, all following one controlled by the player. I need some tips on how to get them to group together and follow without overlapping eachother.
Steyene

Posts: 2,060
Joined: Apr 2006
Rep: 10

View Profile
Jun 30, 2009 3:21 AM #450887
You could just have a function that is called by each of those objects, then in the function have the movement controls.

Edit:

Misread.

Just have then

if(this.x otherobject.x){
this.x +/-= set speed;
}

Then repeat for y, although that will get collisions so then maybe use the distance formulae for the other objects, so that if they are within x distance, their speed changes. Or if they do touch, they stop.
Sawc
2

Posts: 908
Joined: Oct 2006
Rep: 10

View Profile
Jul 2, 2009 7:55 PM #452501
Quote from Steyene
You could just have a function that is called by each of those objects, then in the function have the movement controls.

Edit:

Misread.

Just have then

if(this.x otherobject.x){
this.x +/-= set speed;
}

Then repeat for y, although that will get collisions so then maybe use the distance formulae for the other objects, so that if they are within x distance, their speed changes. Or if they do touch, they stop.


True that would probably work. I don't need them to not touch, just not completely overlap (aka, 20 fish in one spot, so it looks like one fish).
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.