ChrisyChris

Tweening a group and updating the bodies of its children

Recommended Posts

I have a group that contains a large number of children that are P2 physics objects.

When I tween the group the sprites all move correctly, but their collisions occur in the position they were prior to the tween.

Is there a good way to update the position of the bodies of all the children?

Heres some super simplified code incase it helps:

game.physics.startSystem(Phaser.Physics.P2JS);
const collisionGroup1 = game.physics.p2.createCollisionGroup();
const collisionGroup2 = game.physics.p2.createCollisionGroup();

const targetsGroup = game.add.group(0,0);
const ammoGroup = game.add.group(0,300);


const target1 = targetsGroup.create(0,0, "key");
const target2 = targetsGroup.create(50,0, "key");

game.physics.enable(target1, Phaser.Physics.P2JS);
game.physics.enable(target2, Phaser.Physics.P2JS);
target1.body.setCollisionGroup(collisionGroup1);
target1.body.collides(collisionGroup2);
target2.body.setCollisionGroup(collisionGroup1);
target2.body.collides(collisionGroup2);

const bullet = ammoGroup.create(0,0, "key2");

game.physics.enable(bullet, Phaser.Physics.P2JS);
bullet.body.setCollisionGroup(collisionGroup2);
bullet.body.collides(collisionGroup1);

game.add.tween(targetsGroup.position).to(
 {y: "-100"},
 300,
 Phaser.Easing.Quadratic.Out,
 true
);

 

Any help would be greatly appreciated, cheers

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.