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

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.