Search the Community

Showing results for tags 'collisionGroup'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 4 results

  1. Retaliator

    P2 collision callbacks not called

    Hey, I'm developing a Phaser game and been stuck for way too long in this error in my code. Basically I create the player object and everything else from classes to groups and add them to collision groups. Finally I make them collide with body.collides where the callback should happen. I've tried firing the callbacks with just the function name, this.function, function(this.meteors) but nothing seems to work so that the callback gets fired only on contact. Either it fires with every create or never. Here's the main game.js: BasicGame.Game = function (game) { // When a State is added to Phaser it automatically has the following properties set on it, even if they already exist: var playerSpawnX = 300; var playerSpawnY = 300; = game; // a reference to the currently running game (Phaser.Game) this.player = new BasicGame.Player(,playerSpawnX,playerSpawnY); this.gem = new BasicGame.Gem(; this.meteor = new BasicGame.Meteor(; this.hud = new BasicGame.Hud(,this.player); }; BasicGame.Game.prototype = { create: function () { this.timer; this.timer2; = 0; //this.score = 0; var highscore = localStorage.getItem("highscore");;; this.ships =; this.ships.enableBody = true; this.ships.physicsBodyType = Phaser.Physics.P2JS; this.ground =, 2205, 600, 220, 'layers', 'maa'); this.ship = this.ships.create(this.player.create());, false);, 0, 600, 2400); //this.physics.startSystem(Phaser.Physics.P2JS); //////////////////////////////GLOBAL PHYSICS//////////////////////////////////, false, false, true, false); //GLOBAL PHYSICS GRAVITY this.physics.p2.gravity.y = 250; // Create our collision groups. this.shipCollisionGroup =; this.meteorsCollisionGroup =; this.gemsCollisionGroup =; this.ship.body.setCollisionGroup(this.shipCollisionGroup); // This part is vital if you want the objects with their own collision groups to still collide with the world bounds // (which we do) - what this does is adjust the bounds to use its own collision group. this.shipCollisionGroup.collideWorldBounds = true; this.meteorsCollisionGroup.collideWorldBounds = false; //this.gemsCollisionGroup.collideWorldBounds = false; //to make ship hit the sides of screen; //gems group this.gems =; this.gems.enableBody = true; this.gems.physicsBodyType = Phaser.Physics.P2JS; //meteors group this.meteors =; this.meteors.enableBody = true; this.meteors.physicsBodyType = Phaser.Physics.P2JS; this.meteors.gravity = 0; this.timer =; // Set a TimerEvent to occur for meteors and gems this.timer.loop(3000, updateScoreCounter, this); this.timer.loop(1000, spawnGems, this); this.timer.loop(7000, spawnaaMeteoriitteja, this); this.timer.loop(5000, spawnaaPaikallisiaMeteoriitteja, this); this.timer.start(); function updateScoreCounter() {; this.player.score = this.player.score + * 10; console.log(this.player.score); } function spawnaaMeteoriitteja() { for (var i = 0; i < 1; i++) { var meteor = this.meteors.create(this.meteor.create());; meteor.body.setCollisionGroup(this.meteorsCollisionGroup); meteor.body.collides([this.meteorsCollisionGroup,this.gemsCollisionGroup, this.shipCollisionGroup]); meteor.body.collideWorldBounds=false; } } function spawnaaPaikallisiaMeteoriitteja() { for (var i = 0; i < 1; i++) { var static = "true"; var meteor = this.meteors.create(this.meteor.create(,, static));; meteor.body.setCollisionGroup(this.meteorsCollisionGroup); meteor.body.collides([this.meteorsCollisionGroup, this.gemsCollisionGroup, this.shipCollisionGroup]); meteor.body.collideWorldBounds=false; } } function spawnGems() { for (var i = 0; i < 2; i++) { var static = "false"; var gem = this.gems.create(this.gem.create(,, static));; gem.body.setCollisionGroup(this.gemsCollisionGroup); gem.body.collides([this.gemsCollisionGroup, this.shipCollisionGroup, this.meteorsCollisionGroup ]); gem.body.collideWorldBounds=false; } } this.hud.create(); this.ship.body.collides([this.shipCollisionGroup,this.meteorsCollisionGroup], hitMeteor, this); this.ship.body.collides([this.shipCollisionGroup,this.gemsCollisionGroup], hitGem, this); function hitMeteor(body1, body2) { //console.log(body1); console.log("hit meteor"); } function hitGem(body1, body2) { console.log("hit gem"); } }, update: function () { this.player.update(); }, render: function() { this.hud.render(); this.player.render(); }, quitGame: function (pointer) { } };
  2. I have a car similar to this uses P2 physics, CollisionGroup, springs and constraints to simulate the car body and two wheels. Question is how can I make the car "explode" or fall apart when needed? e.g. Collision with object or velocity is too fast, etc. I've tried to remove the springs or constraints but the car flies off the screen unpredictably. Optimally I would like to remove the spring/constraints and just have the 3 car pieces just tumble on the ground disconnected, or I could add random forces to the pieces to simulate a small explosion.
  3. zurcxer

    Collision built in Physics

    Hi Pandajs experts! I have this 2 bodies in a world. body1 is a rectangle.body2 is a circle. I also have a ground. I want to make these 2 bodies fall in the ground. Rectangle falls and hit the ground. But the circle continues to fall. = new game.World(0, this.gravity);var groundBody = new game.Body({position: {x: game.system.width / 2, y: 750},collisionGroup: 0});var groundShape = new game.Rectangle(game.system.width, 100);groundBody.addShape(groundShape);;var x = game.system.width / 2;var y = 600;body = new game.Body({position: {x: x, y: y},velocityLimit: {x: 100, y: 1000},collideAgainst: 0,collisionGroup: 1,});var bodyShape = new game.Rectangle(200, 30);body.addShape(bodyShape);;body2 = new game.Body({position: {x: x, y: y},velocityLimit: {x: 100, y: 1000},collideAgainst: 0,collisionGroup: 1,});var bodyShape2 = new game.Circle();body2.addShape(bodyShape2);;body.mass = 1;body2.mass = 1; Do you have any idea?
  4. pandavigoureux29

    [P2] CollisionGroups and body.collides method

    Hi all, I have some issues with CollisionGroups ( I used to use them for ImpactEvents and am starting to wonder if there are not made just for that) I'll try to make it short and clear : Let's take two collision groups : var playerGroup = game.physics.p2.createCollisionGroup();var groundGroup = game.physics.p2.createCollisionGroup();Now let's take two sprites (assume they are created and physics is enabled) and set their collision groups: player.body.setCollisionGroup(playerGroup);ground.body.setCollisionGroup(groundGroup);With that if I want to enable collisions between these two sprites, I have to do this : player.body.collides(groundGroup);ground.body.collides(playerGroup);So here is the issue : if I put just one of these line, nothing happens. Isn't it enough to tell one body or the other to collide? It seems redundant to me. If that's the way it is, I'll deal with it, but I want to be sure I'm not making any mistake here Thanks