Search the Community

Showing results for tags 'p2'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 335 results

  1. Hi everyone, I am moving forward on my worms project. I have had a problem with P2 physics for a while that I cannot solve and I need to solve it for impact events. THE DEMO: (Chrome Firefox only) THE REPO: THE PROBLEM: On contact with my level (on a hill) my worm keeps sliding veeeery slowly and annoyingly. If the worm is in contact with the level he should stay still (but he won't). ATTEMPTED: Setting the body of the worm properties: velocity.x =0, velocity.y=0, rotation = 0, angle=0, angularDamping =0, angularVelocity = 0, gravityScale = 0.1 (allowGravityScale = true); Setting the game.physics.p2 properties: friction = 1 (tried 0, 1000, 3000 etc), p2.world.defaultContactMaterial.friction = same thing, restitution = 1; CODE OF INTEREST: WORM CLASS - specifically lines 112-117 GAME STATE Thanks in advance for your help!
  2. (http://g.recordit.co/o5HlkT1d5S.gif) Hi, so my setup involves two hills, where the player is rotated to match the slope angle. The first hill rotates the player to an angle of -45° and the second rotates it to 45°. The problem is that once the second rotates the player, the player can just fall through the bodies. My code for the hills is almost identical. (have a different triangle and angle). I think this might be a bug in p2. Any thoughts? EDIT: I've added a second example: http://g.recordit.co/FLgBsRxbeI.gif In this example we can see that the sprites will slide down the first hill, but upon touching the second they will fall through the wold.
  3. Hey all I have this square I am rotating in my simple plat former and it moves along the straight ground perfectly. I am using: enemy.body.rotateLeft(450); This rotates the enemy perfectly, and moves it along, but I also have these hills in my game and when the enemy square encounters the hill it has a terrible time trying to get up it. Is there some sort of property that I can set that would help with this perhaps mass? Or any ideas on how to resolve this? Thanks! P.S I've attached a picture of the square on the hill for reference. Thanks!
  4. Is there a way to suggest new examples? I've created collision groups using P2 physics such that the Tilemap and the player's ship collide, the player's ship and the panda collide, and the Tilemap and the panda do not collide. However, I had trouble getting either the player's ship or the panda to collide with the world boundary. My understanding was that: Since I called "layer.resizeWorld()", I must call "game.physics.p2.setBoundsToWorld(true, true, true, true, ???)" to reset the P2 physics' world bounds. [reason: example lines 48-54] Since I called "this.physics.p2.createCollisionGroup()", I must call "game.physics.p2.setBoundsToWorld(true, true, true, true, true)" to reset the P2 physics' world bounds *with/as a collision group*, -or- call "game.physics.p2.updateBoundsCollisionGroup()" to update the world bounds to be their own collision group, so that other collision groups can collide with the world bounds. [reason: example lines 30-32]. Setting the 5th parameter to setBoundsToWorld() to "true", for "If true the Bounds will be set to use its own Collision Group." (source in documentation) makes calling "updateBoundsCollisionGroup()" extraneous. It seemed like I should be able to call "ship.body.collideWorldBounds = true" somewhere and have it work (or maybe not? ...), but it didn't, and leaving it out entirely didn't work either. Finally I found [this comment] which clarified the order which functions had to be called in. I now have the below example working with: tilemap and ship collide tilemap and panda do not collide world boundary and ship do not collide world boundary and panda collide ship and panda collide CODE: var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.tilemap('map', 'assets/tilemaps/maps/collision_test.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png'); game.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png'); game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png'); game.load.image('ship', 'assets/sprites/thrust_ship2.png'); game.load.image('panda', 'assets/sprites/spinObj_01.png'); } var ship; var map; var layer; var cursors; var panda; var tilesCollisionGroup; var shipCollisionGroup; var pandaCollisionGroup; function create() { game.stage.backgroundColor = '#2d2d2d'; game.physics.startSystem(Phaser.Physics.P2JS); map = game.add.tilemap('map'); map.addTilesetImage('ground_1x1'); map.addTilesetImage('walls_1x2'); map.addTilesetImage('tiles2'); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); // Set the tiles for collision. // Do this BEFORE generating the p2 bodies below. map.setCollisionBetween(1, 12); // Convert the tilemap layer into bodies. Only tiles that collide (see above) are created. // This call returns an array of body objects which you can perform addition actions on if // required. There is also a parameter to control optimising the map build. game.physics.p2.convertTilemap(map, layer); // By default the ship will collide with the World bounds, // however because you have changed the size of the world (via layer.resizeWorld) to match the tilemap // you need to rebuild the physics world boundary as well. The following // line does that. The first 4 parameters control if you need a boundary on the left, right, top and bottom of your world. // The final parameter controls if the boundary should use its own collision group or not. In this case we do require // that because custom collision groups have been set up for the ship and panda. game.physics.p2.setBoundsToWorld(true, true, true, true, true); // collision groups must be created after world boundaries have been finalized/fixed for the groups to collide with the boundaries tilesCollisionGroup = this.physics.p2.createCollisionGroup(); shipCollisionGroup = this.physics.p2.createCollisionGroup(); pandaCollisionGroup = this.physics.p2.createCollisionGroup(); for (var bodyIndex = 0; bodyIndex < map.layer.bodies.length; bodyIndex++) { var tileBody = map.layer.bodies[bodyIndex]; tileBody.setCollisionGroup(tilesCollisionGroup); tileBody.collides([shipCollisionGroup]); } ship = game.add.sprite(400, 200, 'ship'); game.physics.p2.enable(ship); ship.body.setCollisionGroup(shipCollisionGroup); ship.body.collides([tilesCollisionGroup, pandaCollisionGroup]); // Even after the world boundary is set-up you can still toggle if the ship collides or not with this: ship.body.collideWorldBounds = false; panda = game.add.sprite(200, 200, 'panda'); game.physics.p2.enable(panda); panda.body.setRectangle(40, 40); panda.body.setCollisionGroup(pandaCollisionGroup); panda.body.collides([pandaCollisionGroup, shipCollisionGroup]); game.camera.follow(ship); cursors = game.input.keyboard.createCursorKeys(); } function update() { if (cursors.left.isDown) { ship.body.rotateLeft(100); } else if (cursors.right.isDown) { ship.body.rotateRight(100); } else { ship.body.setZeroRotation(); } if (cursors.up.isDown) { ship.body.thrust(400); } else if (cursors.down.isDown) { ship.body.reverse(400); } } function render() { } Lesson: These functions MUST be called in order: map.createLayer() layer.resizeWorld() game.physics.p2.setBoundsToWorld() game.physics.p2.createCollisionGroup()
  5. I have a p2 Object with the following properties this.game.physics.p2.enable(this.player, true); this.player.body.clearShapes(); this.player.body.loadPolygon('playerPolygon','player'); this.player.body.allowRotation = false; this.player.body.fixedRotation = true; this.player.body.immovable = true; this.player.body.setCollisionGroup(playerCollision); this.player.body.collides(ballCollision); this.player.body.kinematic = true; this.player.body.data.shapes[0].sensor = false; this.player.body.collideWorldBounds = true; The above object can only move along its X axis and I want to trigger push/ hit force to its impacting object on collision this.game.physics.p2.enable(this.ball); this.ball.body.setCircle(28); this.ball.body.collideWorldBounds = true; this.ball.body.allowRotation = true; this.ball.body.fixedRotation = false; this.ball.body.adjustCenterOfMass(); this.ball.body.setCollisionGroup(ballCollision); this.ball.body.collides(playerCollision); The above object is always the impacting object whose movement is controlled by gravity and impulse. I'm trying to figure out how to calculate the following:- The point of collision on the body of "this.player" The impulse to apply to the impacting object after collision to simulate a proper/ accurate deflection setting the projected angle and speed/ velocity what properties of the impacting object do I set? Force? AngularVelocity? Velocity?
  6. Hey, I'm building a top-down parking game, for this game we have levels in JSON which (among other things) determines where the player spawns and at what angle. The player consists of three sprites and three bodies (car and two front wheels) that are positioned relatively to each other. Everything goes well, until I try to spawn the car at an angle, because suddenly I no longer know the x and y coordinates of where to spawn the wheels, and it's a bunch of math to figure that out especially as phaser groups fix this problem. Enter example of my problem #1: https://jsfiddle.net/tv4j4tw1/ What I did here is simply create two sprites in a group, positioned them, positioned the group, and then added a body to the sprites. However the bodies spawn completely out of place. If this actually worked properly I'd have no issues. You can ask why do you even need a group here? I do because of the angles mentioned above, if this group would get an angle it'd be a lot harder to figure out the coordinates of the squares. Now we go into where I tried to hack my way out of this problem: https://jsfiddle.net/tv4j4tw1/1/ Ha! This works, I use the group to position the sprites, and then take the sprites out of the group and position them according to their world position while in the group. It's hacky, but I can live with it. Sadly it stops working once I add the angle (which is the whole reason I'm doing this weird stuff): https://jsfiddle.net/tv4j4tw1/2/ The world position is wrong, and the squares still end up in the wrong place. So, I hope I'm doing something fundamentally wrong and getting the hack to work is a silly idea. Halp.
  7. Hey, So I need to check whether a sprite is on the floor using P2 physics. Basically something like Arcade.onFloor() but for P2 physics.
  8. So in my game the player object is made up of several different sprites, so I made a Group called "player," and tried to add an object to it, "rover_proto." I am also trying to use forEach() to change attributes of each item belonging to the group. Here is my code: function createGameScene() { // format: (game, name, addToStage, enableBody, physicsBodyType) player = game.add.group(game.world, 'player', true, true, Phaser.Physics.P2); Rover_proto = player.create(0, 0, 'Rover_proto'); //player.setAll('body', true, true, false); //Group collision player.forEachExists(function (item){ item.body.setCollisionGroup(playerCollision); item.body.collides(wallCollisionGroup); item.body.createGroupCallback(wallCollisionGroup, hurt_rover, player); });}So when I comment out the setAll() is says that "item.body is null." I thought that using game.add.group allows you to enableBody for each item in the group, at least I think it worked that way in Arcade (I am using P2 now which is what is causing me this trouble). So that's when I added in player.setAll(), to hopefully give everything a body. However, if I uncomment it, then the program gives two errors: "TypeError: item.body.setCollisionGroup is not a function" and "TypeError: This.body.preUpdate is not a function." I don't understand why these problems are being caused. I remember using arcade the only way to fix the problem of objects in a group not having bodies was to use the game.add.group() method which I did use in this code. I've also used forEach before, but here it's not working. Is there something I'm missing? Am I using these functions wrong? Can forEach only be called during Update() and not Create() or something? How can I create a body and physics and set collisions, etc. for each object in a group if game.add.group() isn't working (and why isn't it working)? Thank you for your time, --jagd
  9. Hi, I want to scale both sprite and .json physics file, is that possible and if so, how? I ve seen a few posts about that but no answers. Thank you
  10. HI, I am enthralled by the pixi render texture tutorial, but I'm getting an error from the update() function: I've changed the variable names, but I've triple checked that they are consistent. Here's some of my create() code to give an idea what I'm doing. I was hoping to use the render-texture tutorial on top of my working code. Is there a way to get the renderTexture working within an existing p2 game? Thank you. //game.stage.backgroundColor = "#f2f2f2"; game.world.setBounds(0, 0, 450, 800); game.physics.startSystem(Phaser.Physics.P2JS); // create two render textures.. // these dynamic textures will be used to draw the scene into itself render_texture1 = game.add.renderTexture(450, 800, 'texture1'); render_texture2 = game.add.renderTexture(450, 800, 'texture2'); current_texture = render_texture; // create a new sprite that uses the render texture we created above output_sprite = game.add.sprite(225, 400, current_texture); // align the sprite output_sprite.anchor.x = 0.5; output_sprite.anchor.y = 0.5; stuff_container = game.add.group(); stuff_container.x = 450/2; stuff_container.y = 800/2; // now create some items and randomly position them in the stuff container for (var i = 0; i < 4; i++) { var item = stuff_container.create( Math.random() * 400 - 200, Math.random() * 400 - 200, game.rnd.pick(game.cache.getKeys(Phaser.Cache.IMAGE)) ); item.anchor.setTo(0.5, 0.5); } // used for spinning! count = 0; // Turn on impact events for the world, // without this we get no collision callbacks game.physics.p2.setImpactEvents(true); game.physics.p2.updateBoundsCollisionGroup(); game.physics.p2.gravity.y = 0; game.physics.p2.restitution = 0.7;
  11. The following code produces a flipper and four balls that seem to interact as they should. They all collide with each other and the game world bounds. The problem is that the motor isn't working, nor can I figure out how to limit the rotation of the flipper. The flipper goes to the location of the mouseDown event. It is not fixed to a place on the board. This is my intention. I want to use a flipper wherever the player taps and holds. Thank you. window.onload = function() { var game = new Phaser.Game(800, 300, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('flipper', 'assets/sprites/flipper.png'); game.load.image('ball', 'assets/sprites/ball-transparent.png'); // Load our physics data exported from PhysicsEditor game.load.physics('physics_data', 'assets/physics/sprites.json'); } var flipper, flipper_joint, flipper_constraint; var cursors, input_body; var constraint, input_constraint; var constraint_count = 0; var ball1, ball2; function create() { game.stage.backgroundColor = "#f2f2f2"; game.world.setBounds(0, 0, 800, 300); game.physics.startSystem(Phaser.Physics.P2JS); // Turn on impact events for the world, // without this we get no collision callbacks game.physics.p2.setImpactEvents(true); game.physics.p2.updateBoundsCollisionGroup(); game.physics.p2.gravity.y = 10; cursors = game.input.keyboard.createCursorKeys(); // Create our collision groups. One for the flipper, one for the balls var flipper_collision_group = game.physics.p2.createCollisionGroup(); var ball_collision_group = game.physics.p2.createCollisionGroup(); // create joint for flipper flipper_joint = game.add.sprite(200, 150, ''); game.physics.p2.enable(flipper_joint, true); flipper_joint.body.setCircle(25); flipper_joint.body.data.gravityScale = 0; flipper_joint.body.clearCollision(true, true); flipper = game.add.sprite(200, 150, 'flipper'); game.physics.p2.enable(flipper, true); flipper.body.clearShapes(); flipper.body.loadPolygon('physics_data', 'flipper'); flipper.body.data.gravityScale = 0; flipper.body.setCollisionGroup(flipper_collision_group); flipper.body.angle = -35; flipper_constraint = game.physics.p2.createRevoluteConstraint( flipper_joint, [0,0], flipper, [-60,-30] ); input_body = game.add.sprite(0, 0, '', 0); game.physics.p2.enable(input_body, true); input_body.body.setCircle(20); input_body.body.setCollisionGroup(flipper_collision_group); var balls = game.add.group(); balls.enableBody = true; balls.physicsBodyType = Phaser.Physics.P2JS; for (var i = 0; i < 4; i++) { var ball = balls.create(game.world.randomX, game.world.randomY, 'ball'); ball.body.setCircle(25); ball.body.setCollisionGroup(ball_collision_group); ball.body.collides([ball_collision_group, flipper_collision_group]); } // set upper and lower limits for angle in the constraint // NOTE not working flipper_constraint.upperLimitEnabled = true; flipper_constraint.lowerLimitEnabled = true; flipper_constraint.lowerLimit = 0; flipper_constraint.upperLimit = -35; // Not working flipper_constraint.setMotorSpeed(100); } function update() { input_body.body.x = game.input.x; input_body.body.y = game.input.y; if (game.input.activePointer.isDown) { if (constraint_count == 0) { input_constraint = game.physics.p2.createRevoluteConstraint( flipper.body, [0,0], input_body, [0,0], 1000 ); flipper_constraint.enableMotor(); constraint_count = 1; } else if (constraint_count == 1) { flipper_constraint.disableMotor(); game.physics.p2.removeConstraint(input_constraint); constraint_count = 0; } } else { if (constraint_count == 1) { game.physics.p2.removeConstraint(input_constraint); } constraint_count = 0; } } function render() { } }; // end window.onload
  12. I'm working on a modified type of pinball, where the flipper appears where the player taps and holds, and flips when the tap is released. I'm not very far along, but I have gotten the flipper to appear where the screen is tapped. However, I'm quite puzzled by how to proceed with revoluteConstraint, getting the flipper to hinge at a certain point. Again, I need to tap the screen to get a flipper, hold the tap and flip the flipper on release. <!doctype html> <html> <head> <meta charset="UTF-8" /> <title>Flipt</title> <script src="assets/phaser.min.js"></script> </head> <body> <script type="text/javascript"> window.onload = function() { var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('flipper', 'assets/sprites/flipper.png'); game.load.image('ball', 'assets/sprites/ball-transparent.png'); // Load our physics data exported from PhysicsEditor game.load.physics('physics_data', 'assets/physics/sprites.json'); } var flipper; var cursors; var constraint; function create() { game.stage.backgroundColor = "#f2f2f2"; game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); var flipperCollisionGroup = game.physics.p2.createCollisionGroup(); var ballCollisionGroup = game.physics.p2.createCollisionGroup(); flipper = game.add.sprite(300, 400, 'flipper'); game.physics.p2.enable(flipper, true); flipper.body.clearShapes(); flipper.body.loadPolygon('physics_data', 'flipper'); flipper.body.kinematic = true; // Modify a few body properties flipper.body.setZeroDamping(); //flipper.body.fixedRotation = true; ground = new p2.Body(); game.physics.p2.world.addBody(ground); pivotCenter = [0, 0]; offsets = [0, 0]; constraint = game.physics.p2.createRevoluteConstraint(flipper, pivotCenter, ground, offsets); constraint.upperLimit = Phaser.Math.degToRad(0); constraint.lowerLimit = Phaser.Math.degToRad(35); constraint.setMotorSpeed(12); constraint.enableMotor(); game.input.onDown.add(toggleFlipper, this); cursors = game.input.keyboard.createCursorKeys(); } function toggleFlipper(pointer) { if (flipper.alive) { flipper.kill(); } flipper.reset(pointer.x, pointer.y); } function update() { flipper.body.setZeroVelocity(); if (cursors.left.isDown) { flipper.body.rotateLeft(50); } else if (cursors.right.isDown) { flipper.body.rotateRight(50); } } function render() { } }; // end window.onload </script> </body> </html> sprites.json
  13. So I am now making 2d sidescroller, where player can jump with trampoline. But I cannot get it working as I would like to. I made it like this in Physics Editor: But because of using material, which enables bumping, it makes like with arcade physics. (RED IS SHOWING AREA WHERE I WANT IT TO LAND.) So, is there any solution to this? One possible is to cut that jumping area half, and put it together in game with constraints.
  14. Hi, I'm trying to replicate some sort of boomerang effect on an moving object. In short I'm shooting away a sprite but instead of shooting the sprite away in a straight line, I'd like it to move in an 'arc'. Regrettably I have no idea how to achieve this sort of movement. If someone could explain me the theory around such movements, that would be awesome. If you could include a code example, you'd be my hero (of the day). P.S. I'm using P2 physics. Thanks in advance.
  15. Hi all, very new to Phaser and I'm trying to basically make a colour switch kind of game. So I am using p2 physics for the rotating arcs so I can add collision detection later. I had these arcs as graphics in the game but then couldn't add physics to them so they are now sprites in a group call wheel. I have the pivot point of the group set to (85,85). I don't know why but this number works, the sprites are 170x170 but when I try to give the group a pivot point such as (0.5,0.5) it doesn't work I've even tried (0.25,0.25) to try and recreate the (85,85) pivot point. I am trying to do this because when I apply the p2 gravity to the game the wheels pivot point does not move so the wheels rotation gets bigger and bigger. If anyone has a possible solution to this or an alternative method to go about this then please reply! I'm so desperate right now it's not even funny.
  16. The title is pretty self explanatory. Is there any method, in P2 physics, that has the same effect as the velocityFromRotation method in Arcade physics? If there ain't any equivalent, is there a different way to solve this "problem". Thanks in advance!
  17. Greetings! I've been mucking around with this problem for several days, attempting all types of odd solutions and nothing I can come up with works. My problem is this, I spawn a Player object, a sprite with P2 enabled on it. I spawn another Player Object, a sprite with P2 enabled on it. I need both objects to move freely and collide with the world and one another... which they currently do perfectly fine. The issue is when the player objects collide with one another, one always moves the other. I don't wish for either to move the other. Does anyone know of a solution to this using P2? Here's the 'gotcha' .. I need both Player bodies to stay dynamic so they collide with the world objects, and setting them to static or kinematic makes them run through everything which is what I tried. Setting the mass of one to zero or Number.MAX_NUMBER does not work as the game is multiplayer and the server needs to run and have the exact same physics response as the clients, which it doesn't once I do that on the client’s machine. The server doesn't encounter the same order of collision and one player object might become the one with the super mass and run through the other which is not good! Thank you for your time!
  18. I am trying to modify the p2.js example (http://phaser.io/examples/v2/p2-physics/tilemap). I have added a group named explosions which i want to have it's members to collide with the ship but not with the tilemap. From what i've read in the forum, i need to use the collision groups but i cannot understand how (in this case). Using them for the ship is easy and think that using a loop could be ok for the explosions group but for the tilemap it's not that easy. I have read nearly all posts in this forum but i didn't find anything for this case. Any hint ? function preload() { game.load.tilemap('map', 'assets/tilemaps/maps/collision_test.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png'); game.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png'); game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png'); game.load.image('ship', 'assets/sprites/player.png'); game.load.atlas('explosion', 'assets/atlas/explosions.png', 'assets/atlas/explosions.json'); } var ship; var map; var layer; var cursors; var result; var tilesCollisionGroup; var shipCollisionGroup; var explosionsCollisionGroup; function create() { game.physics.startSystem(Phaser.Physics.P2JS); tilesCollisionGroup = this.physics.p2.createCollisionGroup(); shipCollisionGroup = this.physics.p2.createCollisionGroup(); explosionsCollisionGroup = this.physics.p2.createCollisionGroup(); explosions = game.add.physicsGroup(Phaser.Physics.P2JS); explosions.createMultiple(5, 'explosion'); // explosions.body.setCollisionGroup(explosionsCollisionGroup); ? // explosions.body.collides([shipCollisionGroup]); ? map = game.add.tilemap('map'); map.addTilesetImage('ground_1x1'); map.addTilesetImage('walls_1x2'); map.addTilesetImage('tiles2'); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); map.setCollisionBetween(1, 12); game.physics.p2.convertTilemap(map, layer); // how can i define tilesCollisionGroup ? ship = game.add.sprite(200, 200, 'ship'); game.physics.p2.enable([ship],true); ship.body.clearShapes(); ship.body.loadPolygon('physicsData', 'player'); ship.body.fixedRotation = false; ship.body.setCollisionGroup(shipCollisionGroup); ship.body.collides(tilesCollisionGroup); game.camera.follow(ship); game.physics.p2.setBoundsToWorld(true, true, true, true, false); cursors = game.input.keyboard.createCursorKeys(); game.input.onTap.add(addexplosion, this); }
  19. Hi guys, I just wrote a small plugin that enables loading a JSON file generated with PhysicsEditor directly in Panda.js+P2 physics engine. The main goal of this project is to facilitate the process and to provide an efficient the workflow to make great games in Panda.js: You can find the download on Github here: https://github.com/stephan0v/PhysicsEditor-plugin Have a look at the live demo in Panda fiddler here: http://vermeire.home.xs4all.nl/panda/ Requirements: Panda.js frameworkP2 plugin for panda.jsA working version of PhysicsEditor (https://www.codeandweb.com/physicseditor). Instructions: Firstly you have to import the custom exporter into PhysicsEditor. This enables the program to export the physics settings of your choice in a workable JSON notation. Copy the exporter folder in this repository to your local harddrive and link the program to it (see: https://www.codeandweb.com/physicseditor/documentation, at the bottom of the page). Import your personal images in PhysicsEditor and create all the settings you need in second. (Have a look at some of the great tutorials here: https://www.codeandweb.com/physicseditor/tutorials).Export the settings you just generated with the custom exporter Panda-p2 (JSON).Import the JSON in Panda like so:game.module( 'game.main').require( 'plugins.p2', 'plugins.pe_loader').body(function() { game.addAsset('banana.png'); game.addAsset('physics.json'); /* this file is a JSON that looks like this: { "banana": { "mass": 2, "gravityScale": 1, "damping": 0, "angularDamping": 0, "shapes": [ { "type": "POLYGON", "collisionGroup": 1, "collisionMask": 65535, "polygon": [ [98, -0.5] , [106, 0.5] , ...... ] } ] } , ... } */ game.createScene('Main', { backgroundColor: 0xe1d4a7, init: function() { physics = game.getJSON('physics.json'); //Create world this.world = new game.World({gravity: [0, 5]}); this.world.ratio = 100; //now add some fruit var fruit = new game.P2Sprite('banana.png', physics.banana, game.system.width/2, game.system.height/2); fruit .addTo(this.stage); }); });Enjoy!
  20. How can i lock the angle between two sprites which have a revolute constraint atached to each other? Example i have a arm atached to a body with a revolute constraint and i want to that arm keep up at certain angle, i cant reproduce this : ( 'use strict' game = new Phaser.Game(320, 480, Phaser.AUTO, 'space') mainState = preload: -> game.load.image('body', 'public/images/body.png') game.load.image('arms', 'public/images/arms.png') game.load.image('ground', 'public/images/ground.png') create: -> game.physics.startSystem(Phaser.Physics.P2JS) @chest = game.add.sprite(29,53,'body') @arms = game.add.sprite(8,53,'arms') @ground = game.add.sprite(320,70,'ground') game.physics.p2.enable([@chest, @arms, @ground]) robotCollisionGroup = game.physics.p2.createCollisionGroup() environmentCollisionGroup = game.physics.p2.createCollisionGroup() @ground.body.static = true @ground.body.setCollisionGroup(environmentCollisionGroup) @ground.body.collides(robotCollisionGroup) @chest.body.debug = true @chest.body.setCollisionGroup(robotCollisionGroup) @chest.body.collides(environmentCollisionGroup) @arms.body.debug = true @arms.body.setCollisionGroup(robotCollisionGroup) @arms.body.collides(environmentCollisionGroup) @ground.reset(game.world.centerX, game.world.height) @chest.reset(game.world.centerX, game.world.height - 100) @arms.reset(game.world.centerX, game.world.height - 100) game.physics.p2.gravity.y = 600 @chest.body.collideWorldBounds = true @arms.anchor.setTo(0.5, 0.5) @constraint = game.physics.p2.createRevoluteConstraint(@chest, [ -14, -26.5 ], @arms, [ 0, 28]) @cursors = game.input.keyboard.createCursorKeys() update: -> if @cursors.left.isDown @arms.body.rotateLeft(60) else if @cursors.right.isDown @arms.body.rotateRight(60) else return render: -> game.config.enableDebug = true game.debug.spriteInfo(@arms, 32, 32) # Bootstrap game.state.add('start', mainState) game.state.start('start')
  21. The best example I've found of what I'm trying to achieve is this - http://schteppe.github.io/p2.js/demos/topDownVehicle.html However, instead of a car I have a tank, so the movement should be more... tankish, without this front-wheels-turning effect. But this is not a problem. The problem is that my tank's movement looks more like a boat on a water movement. I press UP for acceleration and when I press LEFT or RIGHT it still moves in the same direction for a while, like drifting. And if I release UP button and press LEFT or RIGHT again it drifts as well, without taking into account, that he has turned 90 degrees already. Looks awful in terms of a tank behaviour. In other words, I want my tank to stay "on track" while turning, without such huge drift (or asteroid in space) effect. I suppose this is something I should do in update section. Here is what I have there for now: if (cursors.left.isDown) {tank.body.angularVelocity = -0.75;} else if (cursors.right.isDown) {tank.body.angularVelocity = 0.75;} else {tank.body.setZeroRotation();} if (cursors.up.isDown) {tank.body.thrust(120);} else if (cursors.down.isDown) {tank.body.reverse(70);} else {tank.body.damping = 0.8;}cursors = game.input.keyboard.createCursorKeys(); And a few more, not related to main topic, questions: What kind of P2 library Phaser is using? Is it the same as in the example I've provided in the beginning? Is it technically possible in Phaser to calculate collision angle between shell and an object, e.g. another tank? Thank you.
  22. So im trying to do a space shooter based on p2 physics thrust exemple. in the create method : game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.defaultRestitution = 0.5; this.bullets = game.add.group(); this.bullets.enableBody = true; //this.bullets.physicsBodyType = Phaser.Physics.P2JS; this.bullets.createMultiple(8, 'laser'); this.bullets.setAll('anchor.x', 0.5); this.bullets.setAll('anchor.y', 0.5); Then in the update method i call this function fire: function () { if (this.time.now > this.bulletTime) { var bullet = this.bullets.getFirstExists(false); var p1 = new Phaser.Point(this.ship.x, this.ship.y); var p2 = new Phaser.Point(this.ship.x, this.ship.y - 80); p2.rotate(p1.x, p1.y, this.ship.rotation, false); if (bullet) { bullet.reset(p2.x, p2.y); bullet.lifespan = this.bulletLifespan; bullet.rotation = this.ship.rotation; this.bulletTime = this.time.now + 250; } } } As you noticed I commented the line about settings groups physics to P2JS. The rotation of the laser sprite and its relative positioning to the ship is perfect but right after I uncomment the line; the laser sprite no longer rotate. Its positionning is still relative to the ship rotation but the laser sprite stays straight (point to the top of the screen as the inital image is). Is it suggested to choose ARCADE physics for games using rotations? Also, which property of bullet should i call to make it move on the current angle and direction? Thx
  23. Hi there, how can I disable P2 physics rotating specific body while still be able to use body.rotation property ? I tried kinematic but it ruins collision
  24. Hi, I want to use a P2 body to detect when a player has crossed a certain point.
  25. I need to detect the side on which my sprites collide, I'm using P2 physics. I think there should be something in the contact equation array.