Jump to content

force group collide


devn
 Share

Recommended Posts

Hey. There are 2 sprite physics.
Each has its own group of a collision.

How to make that the collision of these two sprites, they flew away from each other, both, and came off only ONE of the second. The second remained on the spot.

Link to comment
Share on other sites

        var player = t.game.add.sprite(300, 200, 'player');

        t.game.physics.p2.enable(player, false);
        t.game.physics.p2.gravity.y = 1500;

        player.body.clearShapes();
        player.body.loadPolygon('physicsData', 'sluc');
        player.body.kinematic = false;
        player.body.fixedRotation = true;
        player.body.collideWorldBounds = false;
        player.body.setCollisionGroup(app.collide.player);
        player.anchor.setTo(0.5, 0.5);
        player.body.collides(app.collide.cups, function (player, cup) {
            cup.sprite.kill();
        });

create a player

 

        app.el.start = this.game.add.group();
        app.el.start.enableBody = true;
        app.el.start.physicsBodyType = Phaser.Physics.P2JS;
        this.timerStart = this.game.time.events.loop(1000, function () {
            var star = app.el.start.create(this.game.world.width, this.game.world.randomY, 'star');
            star.anchor.setTo(0.5, 0.5);
            star.checkWorldBounds = true;
            star.outOfBoundsKill = true;
            star.body.fixedRotation = true;
            star.body.collideWorldBounds = false;
            star.body.data.gravityScale = 0.1;
            star.body.velocity.x = -500;
            star.body.setCollisionGroup(app.collide.cups);
            star.body.collides([app.collide.player]);
        }, this);

I create stars

The collision star kill.

All good :)
But after the collision of the star players in rebounds

If I do kinematic = true , Gravity has stopped working

Please help) sorry for the English.

Link to comment
Share on other sites

Are you sure you really want a kinematic body here? Kinematic means 'not influenced by gravity or collisions'.

I'm pretty sure you can achieve what you want by using impact events. Let me know if you get stuck working it out (there are a few P2 Impact examples on the site) and I'll see if I can create one quickly.

Link to comment
Share on other sites

On 11.07.2016 at 11:19 PM, rich said:

Are you sure you really want a kinematic body here? Kinematic means 'not influenced by gravity or collisions'.

I'm pretty sure you can achieve what you want by using impact events. Let me know if you get stuck working it out (there are a few P2 Impact examples on the site) and I'll see if I can create one quickly.

I downloaded the game here



Press the space bar

Quote


You see what happens when a collision with the cup?

The player flies away from him. And I need to continue to fly further

Please, help:)

Link to comment
Share on other sites

On 11.07.2016 at 11:19 PM, rich said:

Are you sure you really want a kinematic body here? Kinematic means 'not influenced by gravity or collisions'.

I'm pretty sure you can achieve what you want by using impact events. Let me know if you get stuck working it out (there are a few P2 Impact examples on the site) and I'll see if I can create one quickly.

documentation has 3 status of a physical object

Body.STATIC (the body does not move), Body.DYNAMIC (body can move and respond to collisions) and Body.KINEMATIC (only moves according to its .velocity).

But no one of them does not work gravity.
In principle, suitable DYNAMIC = false if not gravity

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...