Entity see the collide with just 1 entity but not with all it collides[SOLVED]


(billy2000) #1

Hello guys. So i am making a rolling platform witch will move every entity it has on it in a direction.Everything was fine until i tried to put 2 entities on the platform. In this case it moves the 1st entity it founds to collide with.I don’t really know what i’m doing wrong ,but can you guys help me find a way to make the platform move every entity that it is on it? here is the code i use:

private function makeThingsMove():void
	{
		const MOVE_SPED:Number = 2;
		const TYPES:Array = ["Player","Crate"];
		var e:Entity;
		
		if ((e = collideTypes(TYPES, x, y - 1))) {
			e.moveBy( -MOVE_SPED, 0, G.entTypes);
		}
	}

Thx.


(Jacob Albano) #2

You’ll want to use collideTypesInto.

var all:Array = [];
collideTypesInto(TYPES, x, y - 1, all);
for each (var e:Entity in all) {
    e.moveBy(MOVE_SPED, 0, G.entTypes);
}

(Martí Angelats i Ribera) #3

There is a function for this.

var colliding:Vector.<Entity> = new Vector.<Entity>;
collideTypesInto(TYPES, x, y, colliding); //It saves all the entities that collide in the Vector colliding (it can also be an Array).

for each (var e:Entity in colliding)
{
	e.moveBy(-MOVE_SPEED, 0, G.entTypes);
}

PS: LOL. Same answer in less than a minute of diference. The time to write this is too OP.


(billy2000) #4

Hah ty guys. Know i know how to use another useful function XD. thx a lot :smile:


(Martí Angelats i Ribera) #5

I actually found that function randomly while i was looking at the docs a few days ago. XD