Physics can't move children obj

Here is the code

let enemys = this.physics.add.group();

	for(let i=0; i<5; i++){
		let x = Math.round(Math.random()*(1000)+100);
		let y = Math.round(Math.random()*(600)+100);
		let o = this.physics.add.image(x,y,'b');
		o.setDamping(true);
    	o.setDrag(0.99);
    	o.setMaxVelocity(80);
    	o.timer = 3;
    	o.setCollideWorldBounds();
    	random_move(o);
    	enemys.add(o);
	}

I can’t move /accelerate object (random_move) on created and i can’t setCollideWorldBounds(), unless i waited a second to do it.

Btw it’s working fine when i create un-grouped object.

How to fix this?

Thanks

Physics groups apply defaults when adding or creating members.

It will work if you add/create first and then modify after:

for (let i = 0; i < 5; i++) {
  let x = Math.round(Math.random() * (1000) + 100);
  let y = Math.round(Math.random() * (600) + 100);
  let o = enemys.create(x, y, 'b');
  o.setDamping(true);
  o.setDrag(0.99);
  o.setMaxVelocity(80);
  o.timer = 3;
  o.setCollideWorldBounds();
  random_move(o);
}
1 Like

Thank you!

It’s working when i add group after create a physics object