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
    • 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 335 results

  1. 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
  2. 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;
  3. 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
  4. 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
  5. 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.
  6. 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.
  7. 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.
  8. 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!
  9. 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!
  10. 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()
  11. Hello, can you please help me? I require non-rotating crates. Like in this oficial example: http://phaser.io/examples/v2/p2-physics/platformer-material , where I add just one line box.body.fixedRotation = true; to the for cycle creating the boxes. Suddenly, they start to shift and slip. I need them to stay still. How can I fix this? Do you have any idea please? I would be very greatful! I have tried using different materials, but notning helps. Friction is just gone
  12. 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); }
  13. 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')
  14. 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
  15. 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
  16. Hi, I want to use a P2 body to detect when a player has crossed a certain point.
  17. 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.
  18. I'm using P2 physics and I want to disable gravity for some sprites but not all. I've noticed that local gravity is currently unimplemented. I've tried using velocity.y instead of gravity, but it doesn't have the same effect (sprites will float up after reaching the ground). Does any one know how to do this?
  19. Hi, I want to retrieve the tile data from a tile I collide against. I'm using on onBeginContact to capture the collision event. I've combed through the data given by the function but have been unable to find: A coordinate value for the tile (so I can use getTileFromWorldXY) Actual tile data I would then like to retrieve a tile property from the tile data. Does anyone know how to do this?
  20. 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!
  21. Hi, When changing from one state to another any updates to a p2 body's velocity seems to be ignored. I've created the following codepen to illustrate: http://codepen.io/klas/pen/qbMXmm When changing from FirstState to SecondState (with clearWorld = false ) the player sprite stops moving when using p2 physics even though velocity is still applied in the update function in SecondState. If I change to Arcade physics everything works as expected and the player sprite keeps moving. Maybe I'm just missing something how p2 physics work? Is there some kind of reset needed between states? I've tried re-enabling p2 physics for the player sprite in the Second State with no luck. Update: If I call revive() on the player sprite in the create function of SecondState it seems to solve the issue. Not sure why that is? Updated codepen: http://codepen.io/klas/pen/VeGMpq Thanks
  22. Hi there, I have a problem with game mechanics on mobile devices. Mechanics connected with timers. For example, I have a physics character (using p2 physics), which fly up during some time, then falling down. So the problem is my character fly on different heights on different devices. I think it's a problem with performance and game fps. I've tried to connect mechanics with game.time.fps - but it's don't help. Maybe anybody have some ideas what is going on? This is the part of code for example: function fly() { if (timer1.ms < force + 50/*I've tried to add fps here, but no effect*/) { sprite.body.data.gravityScale = -2; } else if (timer1.ms > force - 50) { sprite.body.data.gravityScale = 2; } } var timer1 = application.game.time.create(false); timer1.repeat(myTime, 3, fly); timer1.start(); I use phaser 2.4.4
  23. Hey everyone, I'm creating a snake like game using p2 physics, I'm using body.setCircle() for collision. Each part of the snakes tail is using setCircle() but they are not acting as one. For example if one part of the snakes tail gets hit only that part moves not the whole snake. Is there a way so group collision objects so that act as one? Thanks
  24. Hello everybody ! I'm trying to build some slope and non-regular tiles but i have a lot of problem with collision. The main problem is that when I use moveRight()/moveLeft() on a slope (in this case, just a simple body) and I stop at the middle of the tile, my player just jump like that : On the other case, when I from the top of the tile to the left, my player just fly in the air and slowly land. I tried to tweak a bit the material by setting friction and removed restitution but it don't really change. Maybe it could work if I put a huge amount of gravity but then it will influence other part of the game (like jumping). I have also tried to add a sensor (simple circle) just below the sprite so I could set the x/y velocity at zero when the sensor is in contact with the ground. This is working well but it's not working at all when i'm trying to go down the slope. Basically it moves one px left, set velocity to 0, fall one px (cause of the gravity). move one px left and etc... This is the code if you want to reproduce the problem (I'm stuck with this for many days D:) : create() { this.playerMaterial = this.game.physics.p2.createMaterial() this.tileMaterial = this.game.physics.p2.createMaterial() this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.gravity.y = 400 this.player = this.game.add.sprite(40,40, 'player', 1) this.tile = this.game.add.sprite(80, 272, 'player') this.tile.visible = false this.game.physics.p2.enable([this.player, this.tile]) this.player.body.clearShapes() this.player.body.addRectangle(0, 40, 0, 0) this.player.body.debug = true this.player.body.fixedRotation = true this.player.body.setMaterial(this.playerMaterial) this.player.body.mass = 1.5 this.tile.body.clearShapes() this.tile.body.addPolygon( {} , 0,29, 0,40 , 50, 40 , 50, 0 ) this.tile.body.debug = true this.tile.body.static = true this.tile.body.setMaterial(this.tileMaterial) this.cursors = this.game.input.keyboard.createCursorKeys() this.jumpButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR) let contactMaterial = this.game.physics.p2.createContactMaterial(this.playerMaterial, this.tileMaterial) contactMaterial.friction = 1 contactMaterial.restitution = 0 contactMaterial.frictionRelaxation = 3; contactMaterial.surfaceVelocity = 0 contactMaterial.frictionStiffness = 1e7; contactMaterial.stiffness = 1e7; } update() { if (this.cursors.left.isDown) { this.player.body.moveLeft(200); } else if (this.cursors.right.isDown) { this.player.body.moveRight(200); } else { this.player.body.velocity.x = 0; } if (this.jumpButton.isDown) { this.player.body.moveUp(100); } } So, any idea how can I resolve this problem ? I'm a bit lost. Thanks !
  25. Many link to this: https://www.codeandweb.com/physicseditor on posts relating to obtaining p2 physics collision json. Is there any other software that can obtain the json that is free?