DanEx

Faced a simple error with collision callback

Recommended Posts

this.game.physics.startSystem(Phaser.Physics.P2JS);
        this.game.physics.p2.setImpactEvents(true);
        var wallCollisionGroup = this.game.physics.p2.createCollisionGroup();
        var playerCollisionGroup = this.game.physics.p2.createCollisionGroup();
        var doorCollisionGroup = this.game.physics.p2.createCollisionGroup();
        this.game.physics.p2.updateBoundsCollisionGroup();

// I've created all the necessary collisions as in expamle: https://phaser.io/examples/v2/p2-physics/collision-groups and it works perfect.


player.body.collides(wallCollisionGroup);
            player.body.collides(doorCollisionGroup, wrongDoor, this);

        cursors = this.game.input.keyboard.createCursorKeys();
    }

    wrongDoor() {
        player.body.velocity.x = 0;
        player.body.velocity.y = 0;
        //player.body.setZeroVelocity();
        //player.body.velocity.x = -20000;
        //player.body.velocity.y = -20000;
        //player.body.static = true;
        result = 'You last hit: The wall :)';
        this.game.displayDialogLine('Message', 'text');

    }

 update() {

        player.body.velocity.x = 0;
        player.body.velocity.y = 0;
        
        if (cursors.left.isDown)
        {
            player.body.velocity.x = -300;
        }
        else if (cursors.right.isDown)
        {
            player.body.velocity.x = 300;
        }
        if (cursors.up.isDown)
        {
            player.body.velocity.y = -300;
        }
        else if (cursors.down.isDown)
        {
            player.body.velocity.y = 300;
        }
    }

Hello. I'm making a game where player have to reach the right door and created all the necessary collisions and it works almost perfect, except the call back function wrongDoor. I want to create a dialog line when player collides wrong door and make his velocity = 0 while dialog line is on screen, but I can't. Every time player colldes the door dialog line displays on screen but the player sprite still moves. How can I make him stop on collision with door? 

All the //commented stuff I've tried and it didn't help. I tried to add this function in Update function but it triggers wrongDoor all the time and displays dialog line again and again from the start of the game. I've tried set velocity = -20000 but it doesn't set -20000 velocity, like it doesn't see the player.

On screenshots I press up and right buttons so character moves up and right after wrongDoor triggers.

help.png

help2.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.