Jump to content

Can Detect Collision but bodies pass through p2 physics


lifesuxtr
 Share

Recommended Posts

For some reason in my game i can detect collisions but bodies are actually not colliding they are passing through.

This is how i create player:

Quote

    function createPlayer () {
        player = game.add.sprite(200, 200, 'playerimg');
        player.anchor.setTo(0.5,0.5);
        game.physics.p2.enableBody(player, true);     
        player.body.data.shapes[0].sensor = true;
        game.camera.follow(player);
        player.body.onBeginContact.add(player_coll, this); 
    
        console.log(player.body)
    }


player_coll function fires perfectly fine on collision.

 

Quote

  var tree_object = function (id, type, startx, starty, value) {
        this.id = id; 
        this.posx = startx;  
        this.posy = starty; 
        this.tree = game.add.sprite(this.posx, this.posy, 'tree');
        this.tree.type = 'tree';
        this.tree.id = id;
        game.physics.p2.enableBody(this.tree, true);
        this.tree.body_size = 10; 
        this.tree.body.data.gravityScale = 0;
        this.tree.body.data.shapes[0].sensor = true;
    
    
    }

  

     

Quote

function player_coll(body,test){
        if(body.sprite.type=="tree"){
        console.log(body)
        console.log("collided with tree")
        }


        
        
        
        }

My preload function:

   

Quote

function preload(){
          
        game.stage.disableVisibilityChange = true; // mouse browserdan çıkınca uyutma.2 ekran test için.
        game.scale.scaleMode = Phaser.ScaleManager.RESIZE;
        game.world.setBounds(0, 0, gameProperties.gameWidth, 
        gameProperties.gameHeight);
        //Fizik için P2JS kullanıcaz.
        game.physics.startSystem(Phaser.Physics.P2JS);
        //fizik dünyasının sınırlarını yaratır.(duvarlar)
        game.physics.p2.setBoundsToWorld(true, true, true, true, true)
        //Y nin yerçekimini 0 a eşitle böylece yere düşmeyecek.
        game.physics.p2.gravity.y = 0;
        // Yerçekimini tamamen kapat.
        game.physics.p2.applyGravity = false; 
        game.physics.p2.enableBody(game.physics.p2.walls, false); 
         game.load.image('playerimg', '/assets/player.png');
         game.load.image('background', 'assets/lake.png');     
    
         game.load.image("wood", "/assets/wood.png");
         game.load.image("tree", "/assets/tree.png");
    
        // Collision(çarpma) detectionu aç.
        game.physics.p2.setImpactEvents(true);
    
    
    }

WfYfC.png

As you see in the picture why they are passing through ? 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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