Sign in to follow this  
TrinityCore

Physics P2 BUG!

Recommended Posts

Hello

I would like to know how to fix this problem regarding the positions of objects in phaser with Physics P2.

When placing two objects in the same position "X", each one takes a distinct position, but still phaser indicates that those objects are in the same position "X" being this incorrect.

To avoid confusion I have highlighted one of the objects.

Image: Click Here

For Example:

These are the two objects used in the previous image:

1- Object 1

2- Object 2

I hope that the one who reads this post, know in advance that the dimensions of each of the objects has nothing to do with this problem.

To finish I want to add that the platform where these two objects are located is in position 1200, which would be the height of the map, which is also very bad, since when placing any object in position 1200 that is the limiting part of the Map , These objects should not be visibles

// Game //
PhaserGame = new Phaser.Game(1200, 650, Phaser.AUTO, "PhaserGame");

// World Bounds //
PhaserGame.world.setBounds(0, 0, 5000, 1200);

// Background //
Background = PhaserGame.add.tileSprite(0, 0, 5000, 1200, "BackgroundLevel1");

// Objects //
PhaserObject = PhaserGame.add.group();
PhaserObject.enableBody = true;
PhaserObject.physicsBodyType = Phaser.Physics.P2JS;
CreateObject(0, 1200, 256, 0, "Plataforma001", "", "", PhaserObjects.length+24, "PlataformasBase");
CreateObject(500, 1200-(128-17), 0, 0, "Plataforma002", "PlataformasP2", "plataforma002", PhaserObjects.length+1, "PlataformasAdicionales");
CreateObject(500, 1200-(128-17), 0, 0, "Plataforma008", "PlataformasP2", "plataforma008", PhaserObjects.length+1, "PlataformasAdicionales");
function CreateObject(x, y, IncX, IncY, key, keyPolygon, keyPolygonInternal, count, group){
	for(var i = PhaserObjects.length; i < count; i++){
	    PhaserObjects[i] = PhaserObject.create(x, y, key);
		PhaserObjects[i].Group = group;
		PhaserGame.physics.p2.enable([PhaserObjects[i]], false);
		if(keyPolygon != '' || keyPolygonInternal != ''){
			PhaserObjects[i].body.clearShapes();
			PhaserObjects[i].body.loadPolygon(keyPolygon, keyPolygonInternal);
		}
		PhaserObjects[i].body.static = true;
		PhaserObjects[i].body.setCollisionGroup(PhaserObjectCollision);
		PhaserObjects[i].body.collides([PhaserObjectCollision, PlayerCollision]);
		PlatformMaterial[i] = PhaserGame.physics.p2.createMaterial('PlatformMaterial', 
        PhaserObjects[i].body);
		x += IncX;
		y += IncY;
	}
}

I hope you can give me an indication of what is happening here, thank you!

 

 

Share this post


Link to post
Share on other sites

It is sometimes hard to get on well with Phaser+P2 ... What P2 does is it calculates center of mass and places anchor into it - both your obejcts have x = 500 and both are centered around this point.

In past I had to come up with some solution that allows me to place objects where I want it with anchor which I need. I described it in detail here - it was answer to scaling P2 objects, but solution is complex enough to handle "everything" - scaling, anchoring, positioning:

 

Share this post


Link to post
Share on other sites
On 18/6/2017 at 8:45 AM, Tom Atom said:

It is sometimes hard to get on well with Phaser+P2 ... What P2 does is it calculates center of mass and places anchor into it - both your obejcts have x = 500 and both are centered around this point.

In past I had to come up with some solution that allows me to place objects where I want it with anchor which I need. I described it in detail here - it was answer to scaling P2 objects, but solution is complex enough to handle "everything" - scaling, anchoring, positioning:

 

I get it...

Basically managing P2 is to handle physics in its complexity.
I still do not have what it takes to do it, so I just have to make a small calculation to get the x-y point of the real image and place it in the real position.

Thanks and regards!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.