lifesuxtr Posted August 13, 2018 Share Posted August 13, 2018 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); } As you see in the picture why they are passing through ? Link to comment Share on other sites More sharing options...
lifesuxtr Posted August 17, 2018 Author Share Posted August 17, 2018 I am still having this issue.btw i am moving player with changing coordinates.adding to x y values basicly Link to comment Share on other sites More sharing options...
Recommended Posts