Search the Community

Showing results for tags 'p2'.

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
    • Web Gaming Platform
    • 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 335 results

  1. Hello, The loadPolygon method doesnt change when the shape of animation changes. var ship = game.add.sprite(200, 200, 'player'); ship.animations.add('fly', [0,1,2,3], 10, true);'fly'); game.physics.p2.enable(ship, true); ship.body.clearShapes(); ship.body.loadPolygon('physicsData', 'suu'); ship.body.fixedRotation = true; The loadPolygon is the same. How can i change the shape and the loadPolygon the same time?
  2. titmael

    Rope for Tarzan

    Hi, I read some topics here on how to create a rope system like My hero is moving around and jumping. When pressing a button a rope will be thrown in a direction (from my hero). I think I'll use only one sprite for the rope so it'll be non-flexible rope for the beginning. How to detect collision between my tilemap and my rope in order to fix the rope to the tilemap and transform my hero into Tarzan ? How to fix the rope to the tilemap ? How to change rope angle depending on my hero's mass and speed ? I'm using P2. I think it could be very usefull for a lot of us that kind of system. Thx
  3. Hello ! I have a problem, I don't know if this behavior is the one expected (physics.p2). Here it is: I have a player with doesn't move on the screen, I make platforms come to the player with no friction so the player still doen't move and slide on the platforms. The problem is that the player velocity is taking bigger and bigger values, it's increasing insanly even if the player doen't move. If I set the player velocity to 0 each update, it works the same way... I just don't understand why is it increasing ? It's causing me problems in the devloppement of my game :-( Thanks :-)
  4. Hi all, Wondering if anyone had any experiences with Phaser in IE9. Is it just always going to be slow? I'm using P2 with the built in polyfill provided in the official repo for 2.0.5. Desperately trying to boost performance cross-browser, any thoughts at all would be useful... thank you. Nick
  5. in this live example you can see what i mean.. the interesting thing is, that the platform will push the player into the ground, but not into another platform.. the root of this is the following function that uses the onPresolve equations to find out if the player is touching the moving platform from below and disables the collision completely.. it seems to stop working when the player is on the ground and not moving upwards.. this function allows you to jump through the platform but land on it..."preSolve", onPresolve);here is the code of the function : function onPresolve(presolve){ if (presolve.contactEquations[0]){ c = presolve.contactEquations[0] f = presolve.frictionEquations[0]; var yAxis = p2.vec2.fromValues(0, 1); var y =, yAxis); if (c.bodyB.parent.sprite && c.bodyB.parent.sprite.key == 'platform' && y >= 0){ //if moving upwards c.enabled = false //disable contactEquation f.enabled = false //disable frictionEquation (solves the stuckInPlatform problem) if (c.bodyA.parent.velocity.destination[1] < 15 ){ // velocity < 15 - still inside the platform c.bodyA.parent.velocity.destination[1]-= 0.5; // course correction! } } }}if someone please could help me think why this is happening - i would very much appreciate it.. thx! btw.: it would be better if this function would cycle through all contact equations and find out if bodyA is the player first - in this example the player is the only other object so this works with out the for-loop...
  6. Hi, I'm playing around with P2.js and I wanted to know if it's possible to display the collision area between two sprite. I want to display little explosion right on the collision point, to make collision a bit more real. In the collision callback I'm getting the two collided sprites, a Rectangle and a Convex. There is just height and width in the Rectangle. Am I missing something?
  7. if (cursors.up.isDown && player.body.touching.down){ player.body.velocity.y = -250; } how can i get this to work with p2 physics
  8. Hello there I have a simple question: Is it possible to enable only one or two faces of a polygon body ? Furthermore, would it make me gain performances ? Is it worth it ? Thank you Edit: In fact I'm talking about the physic properties (will it collides or not), maybe it wasn't clear in my post.
  9. Just a quick question - does anyone know if there is ray casting in p2.js? I could probably patch together a line flagged as a sensor and try and find the first intersection - but if it already exists I should probably use it. I want to use it to find if a character is in line of sight or in cover so need to get the first point of intersection of a ray.
  10. Hi all, I'm having an issue where I want to just sense for a collision once and then deactivate one of the physics bodies. But for the life of me, sometimes the collision fires twice or more times, despite my using clearCollision(). Here's what I have: First I set up a collision between the 'iceCube' and the 'basket': iceCube.body.collides(basketCollisionGroup, iceCubeCollision, this);Next, my callback function looks like this: function iceCubeCollision(body1, body2){ console.log("Ice cube collision") body1.clearCollision(true); body1.clearShapes(); console.log ("collision cleared?") ...}Does anyone have any advice? Maybe I'm missing something simple like just checking for a 'collision begin' phase? Any help is appreciated - Nick
  11. Hello, I would like to create a sprite (with a texture and a polygon body) without adding it to the world. I know that without game.add.existing(myEnnemy); it will not be shown, but his body IS in the world (yeah that's strange). Thank you Edit: I would like a kind of SpriteFactory actually with the ability to create multiple instance of the same sprite. Like this: Ennemy = new Ennemy(x,y, key, body);var ennemy1 = Ennemy.createNew();var ennemy2 Ennemy.createNew();var ennemy3 Ennemy.createNew();But it seems a bit complicated.
  12. Hi, I have a sprite and a corresponding json physics for collision polygons. I know how to scale a sprite, but how can I scale the polygons at the same time ? I read but was for polygons created in code. Thx
  13. my game map is 200x20 tiles big - i have 7 layers.. most of them have only a few tiles on them except the mainlayer and the icelayer which contain the ground .. the moment the camera starts scrolling with my player (follow player) the performance drops to 30 frames/second. if i comment out all layers except the mainlayer and the icelayer (so 2 instead of 7 layers) the performance is top !! why is that? i thought the layers are being converted to p2 bodies and then handled as bodies?? touching tiles should be converted to one single body so performance would be even better.. it is definitely not the sheer number of p2 bodies because i created a special test-map (huge with hundreds of independent tiles on one single layer) and the performance was still top.. so scrolling my almost empty layers at the cost of 30 fps ?? is this a bug ?
  14. Holla, amigos! How to slow moving of bodies in P2 physics? I need to substrat 1 pts from body speed per second.
  15. Hi all. I've been encountering this issue since some time now : I know how to initialise P2 Physics game.physics.startSystem(Phaser.Physics.P2JS);When I do this in the create of a State, everything is okay, I can enable bodies on sprites and set my callback events ( onBeginContact ...). I also listen to the broadphase callback and this is working. The thing is, if I move the code above to another State create() function, or in the Game create() function, I lose all my events, the physics seems weird, and the broadphase callback setting trigger an error ( about pairs parent ) Do I have to start a different physics system for each State? That seems weird to me. Thanks
  16. as i said in the title of this thread i think it could be useful for performance to stop p2 calculating every air and ground enemy even if it's 2000 pixels away from me.. in my game (and i think this is true for most jumpNrun platformer games) it would be absolutely ok if the enemies start walking a second before i see them in my current cameraview .. lets say i have 10 enemies and 10 moving platforms on my map.. every step (60 times a second) phaser is calculating all of the objects on the map.. that means 1200 times per second every collision calculation presolve/narrophase whatsoever.. this must be bad for performance ? or are those calculations that simple that this doesn't count? i thought it would be great to tell p2 to only calculate a specific rectangle around my player -- let's say 1000x800 pixels .. every enemy stays on it's place until this rectangle touches it.. is this already possible in phaser somehow??
  17. if i want to change the material of my player in the update function.. it does not set the new material.. it also doesn't keep the existing one.. it just resets the material setting to none.. is there something i have to do after changing the material to have it applied? thx !!
  18. since i discussed this topic in at least 2 other threads more or less "off topic" i thought i would start this one to collect all ideas and approaches to this problem. i created 3 possible solutions at this time but all of them have their obstacles example 1: in this example i use the postbroadphase callback to determine the velocity of the player and decide not to collide if the player is moving upwards to the platform problem: if the velocity goes below the critical point while inside a platform the player will shoot out of the platform with the equations maxForce example 2: 2 sensors (upper/lower) deactivate or reactivate the collision for the players mainshape.. very reliable but far from perfect problem: if you touch a platform while standing on ground you will almost fall through the ground. you could also try to cut the platform (touch it only with the upper sensor) to deactivate the collision and then jump through a thin wall or be invincible to fireballs for example until the next touch down example 3: here i'm manipulating the contact equation. so a contact still happens but i remove the force if the body is touching a platform and coming from below.. this also kinda works but.. problem: jump through is only possible while applying a force.. you can "slide" through the platforms from the sides.. and so on example 4: this one is using the onPresolve method.. this way it is possible to cancel the equation when the player is moving upwards.. (and still get all the information of the possible collision to make further decisions) problem: when the player reaches almost zero velocity and is still inside the platform it will get stuck.. for some reason no force is applied not even gravity (which would be most natural way to get him out of the platform. for the moment i try to catch this case and manually apply a velocity) _______________ you see.. several approaches but none of them is really perfect.. i would like to hear your ideas (browse the code with "rightclick view source)) maybe together we are able to find a perfect solution i'm happy about every idea that could prevent some of the mentioned problems and of course i'm also interested in completely new approaches
  19. Here again. My circles are ignoring world bounds. So there is code:, 0, WINDOW_WIDTH, WINDOW_HEIGHT);; = 0.8;;//...////...////...//chipsCollisionGroup =;this.chips =;this.chips.enableBody = true;this.chips.physicsBodyType = Phaser.Physics.P2JS;//...////...////...//function setupChip(chip, owner, game) { if (chipsCount[owner] < 1) return false; var MAX_MASS = 6; var mass = Math.ceil(Math.random() * (MAX_MASS - 1)) + 1; chip.scale.setTo(convertY(CHIP_SIZE / MAX_MASS * mass) / 64); chip.mass = mass * 100; chip.anchor.setTo(0.5, 0.5); chip.tint = PLAYERS_COLORS[owner]; chip.owner = owner; chip.dragging = false; chip.body.setCollisionGroup(chipsCollisionGroup); chip.body.collides(chipsCollisionGroup); chip.body.setCircle(chip.width / 2); chip.inputEnabled = true; chip.input.start(0, true);;; return true;}//Usally previous function calls like thisvar chip = state.chips.create(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 'chip');setupChip(chip, PLAYER_FIRST,;
  20. Hi, I have recently used phaser and p2 for a university project. Just wondering if anyone would be interested in an example if I put one together? Also, do you think this is something that would interest the guys at Phaser to the point where they could maybe post it in the examples? I used the P2 example from schteppe's Github and had a little help from him too. I would have to work to make it better to show it as an example, but its not bad. Had a little trouble with the scale of physics, tried setting the overall mass to 80 units(whatever they may be) and the gravity to 10 and it did not work, so think I have to figure out the physics units. Tried the pixel to p2 unit conversions with no luck either. I am willing to put in a bit of effort and make a reasonable example if it interests people. Here's a very buggy quick demo, had just finished ragdoll but not implemented any game features. As I said needs work, but let me know if anyones interested as I dont fancie putting in the work for no reason! Cheers.
  21. I'm very new to Phaser (<1 week) but I've stared at the examples and I think it really looks as if I'm doing the right thing, yet collisions refuse to work. In my gameState.create I run the following to set up my P2-physics: game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); game.physics.p2.restitution = 0.8;, -300, 8200, 20000); this.playerCG = game.physics.p2.createCollisionGroup(); this.enemiesCG = game.physics.p2.createCollisionGroup(); this.groundCG = game.physics.p2.createCollisionGroup(); game.physics.p2.updateBoundsCollisionGroup();and later adding the player: this.player = game.add.existing( new Player(this, game, 750, 180, 0)); game.physics.p2.enable(this.player); this.player.body.setCollisionGroup(this.playerCG); this.player.body.collides(this.groundCG, this.player.collidesGround, this); this.player.body.collides(this.enemiesCG); my grounds are the 'fistulaeHair' and are added: game.physics.p2.enable(fistulaHair); fistulaHair.body.kinematic = true; this.ground.add(fistulaHair); fistulaHair.body.setCollisionGroup(this.groundCG); I'm expecting this.player.collidesGround to be called when flying into the ground but nothing happens: It doesn't collide the the collidesGround has a console.log as first line which never fires. I must be missing something very basic it feels like. Also, as a side question, how do I test if I hit the world-end in P2-physics? Any help much appreciated.
  22. 1 collision body 4 sensors for top/left/right/down i want the sensor hovering above the player to set object_above = true; and the sensor to the right of the player to set object_right=true; and so on.. is this possible? and if so - how? i thought maybe i could set onBeginContact events to the sensors individually or somehow find out which sensor reported the collision ??! thx in advance
  23. Hi there, I was just wondering if it's possible to lock the rotation of a body in p2, so it would behave like it would in arcade physics. Or is it possible to mix and match physics bodies between engines? Sorry, kinda new at this. Thank you in advance!
  24. hello everybody! since one of rich's answers to the problem was to use a capsule (instead of a circle/rectangle) i tried to do this (although i don't actually understand how this could solve the problem) one problem with capsules is that it make the mentioned problem even worse (my player can now walk up walls for some reason) the main problem with this is that i don't see the physics body.. i always see a rectangle with the exact size of the sprite but altering parameters of the capsule changes the behavior of my player so i am certain it is applied correctly but not displayed. if i do this: (math.radians is a custom function to convert deg to rad) playershape = player.body.addCapsule(100,15,0,0,Math.radians(90))my player (which is 50 pixels in height) hovers about 25 pixels over the ground.. this seems to be correct because i set the distance between the two points to 100 .. it looks like this:
  25. if this is even possible how do i accomplish this? thx in advance!