Website URL

Twitter

Skype

Location

Interests

Hello,
I have a question regarding the Contact Material example (http://phaser.io/examples/v2/p2-physics/contact-material). How is it possible to totally disable bouncing? Even with a restitution of 0, the sprite still bounces a little. Is it necessary to tweak yet another physical property? Or is it unavoidable to have bouncing in P2?
Thanks!

Hello, I am quite new to phaser and Tiled. I was wondering if anyone could give me some help with understanding on how to create tilemap collisions that are more than just squares with the p2 physics system. Right now every tile has a square collision box, I would like the collision shape to match the tile shape so that I can have slopes and what not. I am a quite a bit confused on the Tiled to phaser workflow especially on what p2.convertTilemap does and how Tiled's collision editor ties into phaser. So far my code looks like this:
preload: function () {
this.game.load.image('mapTiles', "assets/platformer-pack-redux-360-assets/Spritesheets/spritesheet_ground.png");
this.game.load.tilemap('level1', "assets/testmap2.json", null, Phaser.Tilemap.TILED_JSON);
this.game.load.spritesheet('player', "assets/kenney_platformercharacters/PNG/Player/player_tilesheet.png", 80,110, 24);
},
create: function () {
this.game.physics.startSystem(Phaser.Physics.P2JS);
var level1 = this.game.add.tilemap('level1');
level1.addTilesetImage('spritesheet_ground', 'mapTiles');
var wallsLayer = level1.createLayer("layer1");
wallsLayer.resizeWorld();
level1.setCollisionByExclusion([],true,'layer1');
this.game.physics.p2.convertTilemap(level1,wallsLayer);
this.game.physics.p2.convertCollisionObjects(level1,"objectLayer1");
player = this.game.add.sprite(110,80, 'player');
var walk = player.animations.add('walk', [0]);
player.animations.play('walk', 10, true);
this.game.physics.p2.enable(player);
this.game.camera.follow(player);
player.body.setZeroDamping();
player.body.fixedRotation = true;
this.game.physics.p2.setBoundsToWorld(true,true,true,true,false);
cursors = this.game.input.keyboard.createCursorKeys();
wallsLayer.debug = true;
player.body.debug = true;
},
Any help is appreciated!

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.

Hello,
I am working on a project where i can drag an object in X-direction only(like in a abacus).
Is it possible to drag objects in one direction only?
I created a simple task where i can move two objects with mouse (link here).
The issue is that objects are pushing inside each other if i drag one object to another.
I need them to be hard like diamond.
Can i achieve that with p2 js or i have to use box2d plugin (like here).
Also is box2d will be availabe in phaser v3.
Thanks

hi all,
I have a problem about the p2 body and sprite positon
when I enable a p2 body to a sprite, I use
fish.body.setRectangle(fish.width, fish.height);
to set the body shape, but the position of body is far away from the sprite, anyone know what is the problem? thx

Hi!
What I'm trying to do is have 2 objects: one stuck on screen, and one moving with P2 physics.
But from all my testing, what I've gotten down to is that I have 2 choices:
1. No collision between the objects, but able to detect when it goes out of screen
or
2. Objects collide but can't detect when goes out of screen
So my question is... How do I combine that?
This is my code now:
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', {
preload: preload,
create: create
});
function preload() {
game.load.image('block', 'assets/block.png');
}
function create() {
game.stage.disableVisibilityChange = true; //keep running on lost focus
game.world.setBounds(0, 0, 800, 600);
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.gravity.y = 250;
//create objects
var stuck = game.add.sprite(400, 350, 'block');
var stucknon = game.add.sprite(480, 150, 'block');
game.physics.p2.enable([stuck, stucknon]);
stuck.body.static = true;
}
If I have the code for collision groups and collisions, then it will just fall through each other and not collide at all.
The reason I'm using P2 is because I want the realistic/rotating gravity effect
So what do I need to add to make the moving object ("stucknon") fall through the screen and then delete it?

I'm having an issue with scaling a body down with p2, it would appear that the body has an anchor point that is different to the sprite it is for. This causes the body to move up and left when the sprite is shrunk and the body is scaled to match, thus displacing the sprite... any advice?
Note that this only occurs when using a custom poly to create the body

I'm doing P2 physics collisions with:
sprite.body.collides(collisionGroups, callback, this);
and I'm trying to get some info on the momentum transfer of the collision to calculate damage, but I can't find the right values.
What I've tried is to use the velocity difference like this:
var impactSquare = Math.pow(p2BodyA.velocity.x - p2BodyB.velocity.x, 2) + Math.pow(p2BodyA.velocity.y - p2BodyB.velocity.y, 2);
This works ok, but obviously it gives totally wrong values when the bodies fly towards each other and just barely touch, then deltaV is pretty high but there is basically no momentum transfer.
Since there is no V_old and V_new (as far as I know) to get the change of velocity per sprite (pre and post collision) I've tried to look into using the deltaX values:
dx = sprite.previousPosition.x - sprite.position.x ...
but stopped there because it feels like an over-complicated and unreliable way to get something that should be somewhere in the data anyway
Has anybody an idea where to look?
Another (likely over-complicated) idea was to use the onBeginContact method to get the pre-collision velocity and store that somewhere so we can call it in the collides feedback, but ... well feels like there must be something simpler ...

I've played around with P2 physics and created a sprite that has a child attached that can (is supposed to) move freely around the parent.
The child should still contribute to collisions with other objects so I gave it a P2 body as well, but it was behaving very odd. A closer look at the debug data revealed that the collision shape and the sprite image are not at the same position o_O in fact the collision shape is located at an absolute position in the world that relates to the relative coordinates between parent and child and does not move at all.
Here is an example that you can try with the sandbox editor:
game.physics.startSystem(Phaser.Physics.P2JS);
var parent = game.add.sprite(200, 200, 'phaser');
game.physics.p2.enable(parent, true);
parent.anchor.set(0.5);
var child = game.make.sprite(100, 100, 'phaser');
game.physics.p2.enable(child, true);
child.body.static = true;
child.anchor.set(0.5);
child.angle = 0;
parent.addChild(child);
If you look at the attached image you can see the offset. When dragging the parent around with the mouse the collision shape will stay at a fixed position, but it CAN collide with the parent.
This issue might be related to an older discussion:
Any ideas how we can fix this (that don't involve creating the child as a "free" sprite and let it follow the parent via the update() function)?

I have a sprite and a body that both rotate towards the pointer. On collision, though, the sprite sometimes gets turned away from the body. The body continues to point towards the mouse but the sprite does not (see image, definitely not the worst that it can be). I haven't found a way to fix this, anyone know how?

Hi everybody,
I'm working on my first Phaser based game and so far it's really a lot of fun
One thing that keeps giving me some headaches from time to time though is that P2 physics is mostly incompatible with arcade and many tutorials only work with arcade. That seems to start with the sprite bitmaps where everything is rotated 90 degrees
Usually I find some workarounds or I've replaced stuff completely like the Weapon plugin, but now I'm facing an issue with collisions where I'm not quite sure what's the best solution:
Let's assume we have 2 player sprites and 2 enemy sprites and each of them has some bullets to fire. So we create 2 collision groups for the sprites and 2 for the bullets:
var playerCG = game.physics.p2.createCollisionGroup();
var enemyCG = game.physics.p2.createCollisionGroup();
var playerBulletsCG = game.physics.p2.createCollisionGroup();
var enemyBulletsCG = game.physics.p2.createCollisionGroup();
player1.body.setCollisionGroup(playerCG);
player1.body.collides([enemyCG, enemyBulletsCG]);
p1Bullets.body.setCollisionGroup(playerBulletsCG);
p1Bullets.body.collides([enemyCG]);
player2.body.setCollisionGroup(playerCG);
player2.body.collides([enemyCG, enemyBulletsCG]);
p2Bullets.body.setCollisionGroup(playerBulletsCG);
p2Bullets.body.collides([enemyCG]);
enemy1.body.setCollisionGroup(enemyCG);
enemy1.body.collides([playerCG, playerBulletsCG]);
e1Bullets.body.setCollisionGroup(enemyBulletsCG);
e1Bullets.body.collides([playerCG]);
enemy2.body.setCollisionGroup(enemyCG);
enemy2.body.collides([playerCG, playerBulletsCG]);
e2Bullets.body.setCollisionGroup(enemyBulletsCG);
e2Bullets.body.collides([playerCG]);
So far so good, that works fine.
But now we want to change the play-mode and want to activate "friendly fire" and "friendly collisions".
If we add the playerBulletsCG to player1.body.collides(...) and playerCG to p1Bullets.body.collides(...) we get a problem when the bullets are fired from withing the collision box of a player because the players own bullets collide now with his sprite :-(
Obviously we could create additional groups like player1CG, player2CG and player1BulletsCG, player2BulletsCG, but then we also have to add all these groups to the enemies and we need to come up with a whole new structure of initializing all these groups in case we want to support 4 players or more.
So I was wondering if there is any method that says "collide with anything but your own bullets"?
I'm open for any suggestions :-)

Hi
I'm new to phaser and have been trying to use some of the examples as a starting point. I'm planning on using the "Pick Up Object" example, but restrict the area that the tetris shapes are placed in - so that they land on a solid platform. I would then add 3 x buttons to add more of the shapes onto the screen. Example here: https://phaser.io/examples/v2/p2-physics/pick-up-object
Would the best way to achieve this be to build the solid platform using a kinematic sprite as documented here: http://phaser.io/examples/v2/p2-physics/kinematic-body
If not, what is the best way define the area that the shapes are placed in - so they do not fall behind or in front of the platform and buttons?
Thanks!
Tom

So I have been searching a solution for this for 2 days now.
I have a character with physics body.
This character has sprites attached to it with addChild(). Arms, sword, cloak, range indicator.
Range indicator also has a body (only used as sensor/trigger ). However as I found out addChild doesn't work on physics bodies. Sprites move together but I can get Range Indicator's body to move with them. It pretty much sits in the corner.
Since addChild() is no go for physics bodies, is there anything else I can use with this? Really trying to avoid writing a custom function to make the body follow me but running out of options here.
EDIT: Found a workaround for weird child behaviour with bodies.
Added another invisible sprite and made it child to my body.
this.rangePositioner = game.add.sprite(0, 0, 'rangeBlack');
this.rangePositioner.anchor.set(0.5);
this.rangePositioner.pivot.set(0, 40);
this.addChild(this.rangePositioner);
Take its world position with rangePositioner.world ( rangePositioner.position returns 0 ) then set it to my child body.position. I had to dig for some time before I realized sprite.world returns a point. I would expect it to be named something like worldPoint. Anyways I hope this helps someone.

I have a mian body that moves freely on the board. To that body I want to attach a recrangle at a certain offset that would visibly dangle and rotate upon forces affecting the main body.
How could I achieve that? I tried a set of springs, but I can't get the desired effect.

When adding a rectangle to a p2 body you have the option to specify a rotation in radians for the shape which it appears is just passed directly on to the p2 shape constructor (hence the need for it to be in radians instead of degrees as are used elsewhere in Phaser).
I find that if I use any value other than 0 for a rotation, the shape is properly rotated however drawing of the body via the debug parameter ignores the rotation.
Here is a quick codepen illustrating the bug. The character should have a long protrusion coming out the bottom achieved with a rotated rectangle. The physics collision seems to indicate that the rotation has occurred correctly, however the debug shape is not drawn rotated. Notice that he appears to sit a little ways off the ground due to the un-rotated debug visualization of the shape.
It seems to me this must be a bug (or maybe a limitation of the debugbody drawing system) but I thought I would post here first for thoughts. I will likely dig in and see if I can find a fix / workaround for this.
Phaser P2 DebugBody rotation bug (codepen)

Hello,
I read this simple tutorial for beginners: Adventures in Phaser with TypeScript Physics using the P2 physics engine
When two objects are in contact, the event "onBeginContact" must occur. But this does not happen.
I moved the code to codepen:

http://danecekpilar.borec.cz/
Hi guys.
during the development in Phaser i found out, that there is no simple online editor for Making Physics bodies for P2 physics in Phaser.
So i came up with an simple idea. To do a simple online body editor to make json files for Phaser.
I know its super simple and it could do much more things as other desktop body editors can do, but when you want just simple body in two minutes, i think its a good way.
I took me less than two hour to do it, so dont judge it for bad appearance and not efficient solutions for the algorithm.
Maybe ill do things like more bodies in one json file, or auto edge-tracer adn stuff like that, but fell free to comment and come up with your ideas to improve it for the future.
So please, if have have anything to say to this, comment below, i would be pleased.
http://danecekpilar.borec.cz

Part 7 is here, concluding our series: https://loonride.com/learn/phaser/slither-io-part-7
Check out the demo: https://loonride.com/examples/slither-io/slither-io/
Thanks for the support throughout the series! Let me know if you want to see more tutorials like these ones.