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. Hey everyone, I've making a game with various enemies that are made from balls with various abilities. I'd like one of them to grow and shrink over time, and I'm using the P2 physics module. Changing the size of the displayed sprite is easy with sprite.scale.x/y but I'm not sure what the equivalent command is to update the sprite.shape which is used by the physics engine. So when I scale it, I end up with a large sprite but the original hit box. What is the correct way to handle this? Is it necessary to remove and recreate the shape each time I resize my object? -MoragX
  2. Hi All, First post in these forums, I have a current university project using the Phaser engine. As the title suggests I'm attempting a side scrolling Skating game. I've implemented P2 engine to the best of my ability, however, I'm now after some advice on how best to animate an entire collision group - if such a thing is possible! For any interested the link to the latest version is here: Any and all criticisms welcome. Many thanks for any input. James
  3. My first game using Phaser. It was created as an interactive new years greeting card. And while there's still winter in europe, i thought its nice to let the game into the public. link: Ride the sledges and collect bonus points. Avoid knocking down the trees and snowmansand have a good 2015. Game is based on P2 physics engine. It can be played on mobile devices as well with some controls (jumping) and collisions (for trees and snowmans) disabled. The frame rate on mobile varies somewhat betweet 25 and 50 FPS. Controls: up - accelerate down - brake left - rotate left right - rotate right I hope you will enjoy it!
  4. Hi, I have this character that I need to play a walking animation for while on-ground, but a jumping animation when not. I am using "body.onBeginContact()" & "body.onEndContact()" to set a variable "onground" = true/false to choose which animation should play. Since my terrain consist of a bunch of polygon, making for a somewhat edgy ground, my character will needless to say sometime bounce a little bit off the ground, calling these two events very quickly in succession. This happens quite a lot, meaning the player very quickly, just while running along the ground, switches between the two animation modes, which is my first problem. In addition to this problem, there seems to be times when "body.onEndContact()" is called but "body.onBeginContact()" is not called afterwards, so even though the character is standing on the ground he is not considered to be colliding, so I think I need some other function to check for collision as this is erroneous. I am asking anyone here if they have had the same problem and found a good solution. A good solution would in my books be something that can tell if two bodies are touching or have touched within the last few frames or x milliseconds.
  5. 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.
  6. how to achieve something like this: with P2?
  7. How can I add physics to a object like this : ? I am trying to make a breakout game and i want to use an arc that moves and scales in a circular manner ( exactly like the progress bar in the link) , that would be my paddle that would not allow a ball to reach the center. Can this even be done?
  8. Hello, i have this problem i want to call a function when two body of the same group collide. Here is my try: pedone.body.setCollisionGroup(pedoneCollisionGroup); pedone.body.collides([pedoneCollisionGroup, playerCollisionGroup]); pedone.body.createBodyCallback(pedoneCollisionGroup, pedonehitpedone, this);the function pedonehitpedone is not triggered any suggestion? sorry i'm pretty new to phaser and coding...
  9. As the title states, whenever I debug my p2 bodies using the suggested "body.debug = true" method, they show up with the correct size, but are rendered at coordinates 0, 0. I can confirm that the actual physics body is at the correct position, only the debug graphics is at the wrong place. I am using Phaser version 2.2.1, the bodies are static and have "sensor" set to true. If you need more information, please ask. EDIT: I have managed to make an ugly fix for this using: if(developerSettings.debug) { this.body.debug = true; this.body.debugBody.x = this.body.x; this.body.debugBody.y = this.body.y; }This is of cause not pretty, will only render the initial position of the body, and should be unnecessary. It seems like the debugBody position is not being set correctly in the core.
  10. i created 2 sprites and added p2 body for each of them first on is the player it is , second is static and when i checkd for collision for each of them it works but only if the second one is not moving when i move the second sprite around the world for example this.update = function(){ block.body.x = block.body.x -1; }; it is not collide with the other sprite what is the problem :/ !
  11. Hi all!, I'm a newbie in coding game and starting from example and a lot of google i came up with my first test. You can see a live preview here using my parent site to test... The problem i'm having is that i wish the zombies to have a little of drag and also that when they hit each other, with a certain velocity they will play the dead animation. Also adding mobile and mouse control... Here is the code: var w = window.innerWidth * window.devicePixelRatio, h = window.innerHeight * window.devicePixelRatio;var game = new Phaser.Game((h > w) ? h : w, (h > w) ? w : h, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });function preload() { game.load.spritesheet('car', 'assets/car.png', 76, 47); game.load.image('ice', 'assets/ice.jpg'); game.load.spritesheet('pedone', 'assets/pedone.png', 32, 48);}var car;var cursors;var score = 0;var scoreText;var land;function create() { game.physics.startSystem(Phaser.Physics.P2JS); land = game.add.tileSprite(0, 0, (h > w) ? h : w, (h > w) ? w : h, 'ice'); game.physics.p2.setImpactEvents(true); game.physics.p2.restitution = 0.7; scoreText = game.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#000' }); var playerCollisionGroup = game.physics.p2.createCollisionGroup(); var pedoneCollisionGroup = game.physics.p2.createCollisionGroup(); game.physics.p2.updateBoundsCollisionGroup(); var pedones =; pedones.enableBody = true; pedones.physicsBodyType = Phaser.Physics.P2JS; for (var i = 0; i < 70; i++) { var pedone = pedones.create(,, 'pedone'); pedone.body.setRectangle(32, 48); pedone.body.setCollisionGroup(pedoneCollisionGroup); pedone.body.collides([pedoneCollisionGroup, playerCollisionGroup]); pedone.body.collides(pedoneCollisionGroup, pedonehitpedone, this); // this is my tentative but not work pedone.body.angle = game.rnd.integerInRange(-180, 180); var angleped = pedone.body.rotation + (Math.PI/2); pedone.body.velocity.x = -30 * Math.cos(angleped); pedone.body.velocity.y = -30 * Math.sin(angleped); pedone.body.mass = 0.3; //test for drag pedone.body.linearDamping = 1; //test for drag pedone.angularDamping = 1; //test for drag pedone.damping = 1; //test for drag pedone.inertia = 0.2; //test for drag all no effect } pedones.callAll('animations.add', 'animations', 'walk', [0, 1, 2, 3, 4, 5, 6, 7]); pedones.callAll('play', null, 'walk', 7, true); car = game.add.sprite(200, 200, 'car'); game.physics.p2.enable(car, false); car.body.setRectangle(76, 47); car.body.allowRotation = true; car.body.immovable = true; car.body.mass = 1; car.body.setCollisionGroup(playerCollisionGroup); car.body.collides(pedoneCollisionGroup, hitpedone, this); cursors = game.input.keyboard.createCursorKeys(); this.input.onDown.add(click, this); //mouse and touch control test not working this.input.onUp.add(release, this); //mouse and touch control test not working this.input.addMoveCallback(move, this); //mouse and touch control test not working}function click() { var angleclick = car.body.rotation + (Math.PI); car.body.velocity.x = -500 * Math.cos(angleclick); car.body.velocity.y = -500 * Math.sin(angleclick);}function release() {}function move() {}function hitpedone(body1, body2) { body2.sprite.animations.add('dead', [7, 8, 9, 10]);'dead', 12, false,true); body1.sprite.animations.add('schizzo', [1, 2, 3]);'schizzo', 1, false); score += 10; scoreText.text = 'Score: ' + score;}function pedonehitpedone(body1, body2) { body2.sprite.animations.add('dead', [7, 8, 9, 10]);'dead', 12, false,true); score += 10; scoreText.text = 'Score: ' + score;}function update() { car.body.setZeroRotation(); car.body.setZeroVelocity(); var angle = car.body.rotation + (Math.PI); if (cursors.left.isDown) { car.body.angularVelocity = -7; } else if (cursors.right.isDown) { car.body.angularVelocity = 7; } if (cursors.up.isDown) { car.body.velocity.x = -500 * Math.cos(angle); car.body.velocity.y = -500 * Math.sin(angle); } if (cursors.down.isDown) { car.body.velocity.x = 500 * Math.cos(angle); car.body.velocity.y = 500 * Math.sin(angle); }}function render() {}Thank you very much if you will help! Have a nice day !
  12. im a beginner in Phaser.js game development and i want to create static body to group , with p2 physic system i created the group and then started the physic system. var block_group =; var Y = 20; for (var i = 0; i < numberOfBlocks; i++) { block_group.create(400,Y,'block'); Y = Y +15; }; game.physics.startSystem(Phaser.Physics.P2JS); block_group.enableBody = true; block_group.physicsBodyType = Phaser.Physics.P2JS; when i print block_group.body it gives me undefined so i tried using forEachAlive and it stile the same however it works fine for single sprite , but with a group it is not working .
  13. Hey there, I was wondering whether there was an easier of dealing with curvy shapes such as the one I have attached. I've done a similar shape that was much smaller using P2 physics and handing in to physics a JSON of smaller rectangles to handle collisions. This took me quite a while though especially to get something that acted smoothly. Is there any way of adding either physics data or drawing this shape with P2 so that it can collide well with other objects? Thanks in advance!
  14. I'm developing a game which makes use of the P2 physics system. I have a group of sprites with static P2 bodies which must collide with another sprite with a dynamic body. This all works dandy until I call the .kill() method on one of the static bodies and then respawn it somewhere else via .reset(x,y). After reseting it, it no longer collides with the dynamic body? After hours of debugging I've figured out that if I make the bodies static then collisions still work after a kill/reset. This doesn't help me that much however as I need them to be static. I've made a jsfiddle to illustrate the problem: (NOTE: click the big boxes to kill/reset them) Cheers!
  15. Can anyone guide me the way to do a jump on P2? I have read this article about the jump on P2, but what I actually wanted is that: I want to jump depend on how I press the key : example: if I press slightly, it will jump a little and if I press hardly, it will jump high. please give me a demo. Thanks you for helping.
  16. I'm trying to figure out how to best detect overlap between a tileSprite that's resizing and relocating every frame (I use it to visualize a physics spring) and a group of sprites with circular P2 bodies attached (in order to remove the spring upon contact). I tried attaching a P2 body to the tileSprite (spring) and call body.setRectangleFromSprite() every frame like so: spring.body.x = x;spring.body.y = y;spring.width = width;spring.body.angle = angle;spring.body.setRectangleFromSprite();...and was planning to enable the body's data.shapes[0].sensor for overlap detection as described here: However, for some reason the body's angle is different from the sprite's angle (see attached images) (I'm ignoring the body's offset for now). The body appears close to perpendicular to the sprite when the sprite is almost vertical, while the body almost matches the angle when the sprite is close to horizontal. Math has always been my Achilles' heel, but this smells like a sine/cosine problem to me. Am I doing something wrong? Or is there an altogether better way of going about this? Many thanks in advance to this wonderful community!
  17. Hi all, In my game I have circles which are spawned and then are tweened over time to adjust their scale. This is working however, I want to detect when two circles collide and run a function when this happens. All the circles are in a group. I have tried using arcade physics however after researching I found out that collision detection only works if the sprites have motion, and mine do not they are just being tweened, arcade physics also doesn't have a circular hit box. I then decided to look into P2 physics which does work and the collisions are detected, however, it causes the circles to move off screen, this can be solved by making each circle static but then collisions are not detected between them. Also, without the circles being static although the collisions are detected they are detected when the circles are not even touching. Thanks for your help.
  18. Hey Everyone, I just completed and released a simple, physics based game that user Phaser. As the circle, your job is to avoid the triangles and gain points by hitting the rectangles. The game gets progressively harder after certain point thresholds are reached. The level change is indicated by the player (circle) changing colors. The game is intended to be challenging, however there is strategy in controlling the player which will allows for much higher scores. Leaderboard and achievements have been included on each platform using Google Play Games and iOS Game Center. The iOS version has a new version with bug fixes waiting for review (current version still playable), but the Android version is up-to-date. Feedback is welcome. Thanks
  19. Hello everyone! I am making a game and i have some objects with triangular shape. I use p2js just for collision detection with onBeginContact (everything else is handled manually, like movement etc.). So i am wondering if there is a less expensive way to detect polygon collision. Thanks
  20. So currently I am making a 2D game with Phaser P2 Physics that involves a ball rolling along, sort of like a platformer, I am trying to make it both difficult for the ball to roll up a hill and then easy for it to roll down. I know increasing the gravity will do the trick, but then the global gravity will be increased and the ball will basically be sucked to the ground. I've performed some tests and I had to change the gravity to about 10000 to get it to roll down at a noticeable speed. Now is there an easier/better way to do this using some of the Phaser P2 Physics attributes? I appreciate any and all help! Thanks!
  21. i opened this thread because the title of the thread where i found this problem is misleading.. so sorry for the double post as you can see in the attached image the physics body of a fast moving sprite is sometimes far from directly below the sprite. this is usually not a problem but when i try to make another spirte follow the first sprite it will always follow the physicsbody which is at a different position this looks weird and renders the whole thing unusable.. in my case this should be a visual aid but if its pointing towards the wrong x and y coordinates it makes no sense
  22. Hey all, I am currently trying to rotate a ball along the ground using the rotateLeft and rotateRight methods included in P2 physics. Currently the behavior is that the ball rotates but it doesn't seem to move upon rotating but rather it gets a couple of revolutions in and then glides across and then even when the ball has stopped rotating it continues to slide across. I'm guessing this has to do with there not being any friction, is there any way to get friction on the world balls or is it better to just add a material and have the ball rotate along it? Any help is greatly appreciated thanks! Example here:
  23. Hi, I loaded my tiles with game.physics.p2.convertTilemap() and it works. However, each tile is a square block and my "player" is floating on slanted tiles (similer to problem mentioned in here). Using Tiled editor's "Tile Collision Editor", i defined the polygon I want but Phaser does not seem to pick it up. Part of the exported JSON looks like this (tells me that the polyline was created): "tilesets":[ { "firstgid":1, "image":"tiles.png", "imageheight":374, "imagewidth":374, "margin":0, "name":"tiles", "properties": { }, "spacing":2, "tileheight":32, "tiles": { "57": { "objectgroup": { "draworder":"index", "height":0, "name":"", "objects":[ { "height":0, "name":"", "polyline":[ { "x":0, "y":0 }, { "x":32, "y":-32 }], "properties": { }, "rotation":0, "type":"", "visible":true, "width":0, "x":0, "y":32 }], "opacity":1, "type":"objectgroup", "visible":true, "width":0, "x":0, "y":0 } } }, "tilewidth":32 }, { "firstgid":122, "image":"items.png", "imageheight":270, "imagewidth":270, "margin":0, "name":"items", "properties": { }, "spacing":2, "tileheight":32, "tilewidth":32 }, { "firstgid":186, "image":"sprites.png", "imageheight":100, "imagewidth":238, "margin":0, "name":"sprites", "properties": { }, "spacing":2, "tileheight":32, "tilewidth":32 }]How do I load the tile's collision polyline/polygon in Phaser when loading the tiled layer?
  24. I'm trying to implement a platformer using p2 physics. There's known issue with tiles converted to collide boxes with p2.convertTilemap(). I can propose an example of how it affects gameplay: It turns out that length of narrowphase.contactEquation list sometimes is 0 even when the player crashes into the tiled wall. The issue is being discussed from time to time (e.g. but seems to have no other solution but "use polylines instead of tiles". The trouble is that my tilemaps already have lots of collide tiles. So I wonder if there is a way to modify checkIfCanJump() function (the function is taken from and in my example is modified as playerTouching() according to Maybe I should tinker deeper with threshold = 0.5 or use different collide equation list than
  25. I'm creating 2 circles using graphics and adding them to sprites. I'm trying to make the sprites contact each other, but the function added on onBeginContact is called before the objects touch. I have a jsfiddle here: Can anyone please let me know why there is space between the two bodies yet they appear to have made contact?