Jump to content

CollisionGoups for Groups


valueerror
 Share

Recommended Posts

so i'm testing collision groups in a very simple testgame and with only 4 different collision groups i have a lot to do now..  so i wonder if it would be possible to set some of the settings directly to the group.

 

an example:

 

playerCG = game.physics.createCollisionGroup();

groundCG = game.physics.createCollisionGroup();

 

 

platforms = game.add.group();

plattforms.physicsEnabled = true;

platforms.bodies.setCollisionGroup(groundCG);

platforms.bodies.collides(playerCG);

 

 

player.body.collides(groundCG);

 

and another question: is it possible to be in more than one collision groups?

thx in advance!

 

 

 

 

 

Link to comment
Share on other sites

so.. after playing around another 2 days with collisiongroups i think more and more collision groups should be handled like materials..

maybe i just can't see the advantage of the current approach but to me as newbee it looks like to much work..  i know 2.0 is in the middle of development - so if this is work in progress and will change in the next weeks anyway.. please ignore this post..  

 

in the material world you do the following:

 

 

define materials  (what is the parameter in the brackets for? e.g. 'ground' or 'player') 

var groundMaterial = game.physics.createMaterial('ground');var playerMaterial = game.physics.createMaterial('player');

set materials to physics bodies

ground.body.setMaterial(groundMaterial);player.body.setMaterial(playerMaterial);

setup what happens when material1 contacts material2 globally..

game.physics.createContactMaterial(playerMaterial, groundMaterial, { friction: 4, restitution: 0.6 })

in the collision world you have to do it this way to achive collision between to physics bodies:

 

define collision group

var playerCG = game.physics.createCollisionGroup();var groundCG = game.physics.createCollisionGroup();

set collison group and define with which group this body has to collide

ground.body.setCollisionGroup(groundCG);ground.body.collides(playerCG);

player.body.setCollisionGroup(playerCG);player.body.collides(groundCG);
this is i little bit inconsistent.. while this seems oke or as much work as materials in this example, think of a typical platformer where there are several different objects and all of them are in the "groundCG"  ... an for every single object you have to define the same thing over and over again.. playerCG collides with groundCG and vice versa...
 
why no do something like this (pseudo):
game.physics.createCollisionScenario(playerCG, groundCG, collisionCallback, processCallback, collisonContext, options)

so you define it once and every(physics)body in those groups collides as defined.  (and of course you can have a custom processCallback like in 1.x to create platforms where you can jump through from below but still stand on ;-) )

 

 

 

______________

and btw.  how do i set a collision group to the game.world?? for materials there is:

game.physics.setWorldMaterial(groundMaterial);

but there is no..

game.physics.setWorldCollisionGroup(groundCG);

once you define collisiongroups everything needs to be defined explicitly - nothing just collides anymore and the player walks right through the world bounds...   :(  (there is a setting to create it's own collision group when setting the worldbounds - but what then? how is this group named? how to setup the player to collide with it? collideWorldbounds seems to do nothing at the moment in connection with collision groups.

Link to comment
Share on other sites

this method "in the collision world you have to do it this way to achive collision between to physics bodies" actually doesn't work on my test game :\

 

there is a guide for new collision system of 1.2/2.0 version of phaser?

http://lotti.github.io/phaserTut/ try turning the variable "collisides" to true on the first row of init.js: the callback is never called and the physic collision disappear!

 

i looked at your super mario clone to make the gravity work. no success with collisions!

Link to comment
Share on other sites

this is a long shot because i didn't test your code.. but i think the collision groups don't work because you set the collision circle AFTER setting the group and the material..  i believe you have to FIRST set the circle.. and then set the other options because they need a circle to be proper initialized..   

 

so you would set  

 

name

anchor

scale

physicsenabled

circle

mass

damipng

material

collisiongroup

 

and colliding with worldbounds does not seem to work at the moment

Link to comment
Share on other sites

great! it works! :) please pin this post :P

 

now i have another problem: if i set static = true then to false (same with mass from 0 to <a value>) when the mouse clicks, the position, the scale and the position of the collider are all fucked off :P but i will wait the final release.

Link to comment
Share on other sites

I have a similar question:

I've got a prefab class that inherits from Group.

var PipeGroup = function(game, x, y, collisionGroup, collidesWith) {	Phaser.Group.call(this, game);	var topPipe = this.create(0,0,'pipes');	topPipe.physicsEnabled = true;	topPipe.body.kinematic = true;	topPipe.body.setRectangle();	topPipe.body.setCollisionGroup(collisionGroup);	topPipe.body.collides(collidesWith);	this.x = x;	this.y = y,};PipeGroup.prototype = Object.create(Phaser.Group.prototype);PipeGroup.prototype.constructor = PipeGroup;

And in my main game's create function:

create = function() {  ..        this.playerCG = game.physics.createCollisionGroup();  this.pipeCG = game.physics.createCollisionGroup();  // add our player to the stage  this.player = this.add.sprite(game.world.width/3,220,'bird');  // enable physics on our player  this.player.physicsEnabled = true;    // add our player to the player collision group  this.bird.body.setCollisionGroup(this.playerCG);  this.bird.body.collides([this.pipeCG], this.death, this);  ..  game.time.events.loop(Phaser.Timer.SECOND,this.generatePipes, this);}

and generatePipes looks like:

generatePipes: function() {  var pipeY = game.rnd.integerInRange(-120,120);  var pipes = new PipeGroup(game,game.world.width + 32, pipeY, this.pipeCG, this.playerCG);  this.player.body.collides([this.pipeCG], this.death, this);}

However, the player is never colliding with the pipes.

 

What gives?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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