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. Hello, I'm trying to set collision with Tiled using the "Tile Collision Editor" on Tiled but I can't make it work on game. Basically I want to create a Polyline for each different Tiles so I don't have to copy/paste the polyline objects in the object layer. For the moment I use one big Polyline object on a object layer that follow my map but it's not viable beause I have to draw all my tiles manually. Here is the part of the code I use to incorporate the object layer (I'm using ES6). It's working but it's not what I want : this._map = new Map(this._game, mapName);// ...this._map.addTilesetImage(tilesName, tilesName);this._blocksLayer = this._map.createLayer('collision');this._blocksLayer.resizeWorld(); this._game.physics.p2.convertTilemap(this._map, this._blocksLayer); this._game.physics.p2.convertCollisionObjects(this._map, 'test'); // where 'test' is the name of my layerThanks in advance for the help !
  2. I tried to play around with some complex polygons and run into some issues. I first fooled with code&web physics editor and that work like supposed. Then, i took a look on JSON format and tried create similar one by hand. After some trial and error i got it right. It collided properly with world borders and body debug looked right. However, objects didn't collide properly with other objects and now I'm wondering why.. Also, one weird error said something like "Convex polys must be in conter-clockwise order" So can anyone open this mystery, how does convex polygons collision work behind the scenes? I also noticed that shapes were divided into multiple smaller shapes in JSON. Is this simply to prettify JSON or is there actually a reason behind this?
  3. I'm currently using p2 to move a ship in a similar way as shown in the image above (Note: the demo above only looks like it works, but it actually moves in basically any random direction except the one is facing) The problem number one is the sprite of the ship. The angle "cero" seems to be by default facing up in p2, but in my sprite it's not quite looking up. The second issue comes with the "snapping". I wan't to make the ship always face either 45degrees, -45degrees, 135degrees or -135degrees. This was the idea the hole time. I'm thinking that maybe I'm over-complicating myself, and I should have just make the sprite flip and change the direction at once, but now that I've seen how it looks like when the sprite "slowly rotates" from one direction to the other, I would like to achieve the same result! This is my code so far on create() //create player player = game.add.sprite(game.world.centerX, game.world.centerY, 'ship'); //enable player physics game.physics.p2.enable(player); player.body.collideWorldBounds = true; player.body.angle = (Math.PI/4); // 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 (false) controls if the boundary should use its own collision group or not. In this case we don't require // that, so it's set to false. But if you had custom collision groups set-up then you would need this set to true. game.physics.p2.setBoundsToWorld(true, true, true, true, false); /* Player animations version 1.0 normal: the player is in first frame. May as well be not moving. begin_fly: the player is begining to fly. fly: the player is flying. */ player.anchor.set(0.5, 0.5);on update() if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { player.body.rotateLeft(100); } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { player.body.rotateLeft(-100); } else { player.body.setZeroRotation(); console.log(player.angle); } player.body.thrust(400); //MOVE FOWARD CONSTANTLYTLDR: The code does the trick okey so far but: 1. The player is facing a wrong direction 2. Once you stop pressing left or right, the player will remain in whathever angle it was left, instead of "snapping" to a 45degree angle. Any idea, though, recomendation, etc. would be higly appreciated! :ยท3
  4. There is an object with 6 surfaces. Created with the help of loadPolygon. How can I determine the surface, which the object encountered? Sorry, I do not speak English.
  5. So I have player and walls as material. Wall collision is made in Tiled polylines. How I can trigger event every time, when player collides to walls? this.walls = this.game.physics.p2.convertCollisionObjects(this.map, 'Object Layer 1', true); for (this.wall in this.walls) { this.walls[this.wall].setMaterial(this.wallMaterial); } this.layer1 = this.map.createLayer('Tile Layer 1'); this.collision = this.map.createLayer('Object Layer 1');I tried to set postbroadphase callback like in example, but it is not working. I have tried to set collision to wall and collision. But it gives just error. this.game.physics.p2.setPostBroadphaseCallback(this.restart, this);restart: function (body1, body2) {if ((body1 === this.player && body2 === this.collision) || (body2 === this.player && body1 === this.collision))
  6. Hey, I'm trying to add a custom collision polygon for a hexagon. I've measured the corners of my hexagon in illustrator: 28, 055,1655,4828,00,480,16 When I try to implement it:game.physics.p2.enable(hexagon, true);hexagon.body.clearShapes();hexagon.body.addPolygon( {} , [[28,0],[55,16],[55,48],[28,0],[0,48],[0,16]]);The collision polygon is not visible at all (in debugger). I've never tried adding a custom polygon so I have no idea what I'm doing wrong. Thanks.
  7. Video of issue: https://www.dropbox.com/s/td88t29bxq7jwqk/Phaser-wrong-overlaping.mov?dl=0 Background should change when zone and gift are overlapped but setPostBroadphaseCallback fire event on wrong time. I think It happens maybe because zone looks like a rectangle... This is code for the video you see above: http://paste.ofcode.org/QE7KjbDy4bXLLYNQDKDDnY
  8. 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.
  9. when I exit from full screen my player (with its own collision group) stops rebounding against the world edges i've tried various combinations of these with no luck this.game.scale.stopFullScreen();this.game.world.setBounds(0,0,480,32*11*10) // or ...// this.layer1.resizeWorld()this.game.physics.p2.updateBoundsCollisionGroup();this.game.physics.p2.setBoundsToWorld(true, true, true, true,true)thanks for any advice was also mentioned here by somebody else http://www.html5gamedevs.com/topic/15385-issue-with-p2-stopfullscreen-collisionmask-world-bounds/
  10. sorry for the double-posting. forum was playing up! i'll close this one
  11. I have a tilemap and i want the tiles on one layer to be collectible. converting it all to sprites causes too much slowdown I manage to get p2 collisions but the problem with the (unoptimized) tilemap conversion is there's no link between the physics body and the tile it represents var collectibles = this.game.physics.p2.convertTilemap(map, this.layer1,true,false)just returns p2 bodies and no relevant tile data Is there a way to get the tile related to a p2 body? i ended up cheating and doing this. but it's not perfect.... overlap=8this.map.removeTileWorldXY(this.player.position.x, this.player.position.y,32,32,this.layer1)this.map.removeTileWorldXY(this.player.position.x-overlap, this.player.position.y-overlap,32,32,this.layer1)this.map.removeTileWorldXY(this.player.position.x+overlap, this.player.position.y-overlap,32,32,this.layer1)this.map.removeTileWorldXY(this.player.position.x-overlap, this.player.position.y+overlap,32,32,this.layer1)this.map.removeTileWorldXY(this.player.position.x+overlap, this.player.position.y+overlap,32,32,this.layer1)thanks for any suggestions J
  12. 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!
  13. I am having difficulty having the ground stop any object other than player (not even quite sure why player stops). The other object(s) fall straight through. I thought it would be a simple as creating another collision group, but when I do so the game does not run. Here is what I am trying --- create: function () { this.physics.startSystem(Phaser.Physics.P2JS); this.physics.p2.setImpactEvents(true); this.physics.p2.gravity.y = 1200; this.world.setBounds(0, 0, 2000, 600);//(x, y, width, height) this.physics.p2.setBoundsToWorld(true, true, false, true, false); this.physics.p2.friction = 5; clouds = this.add.tileSprite(0, 0, 2048, 600, 'clouds'); ground = this.add.sprite(this.world.width/2, this.world.height-24,'ground'); this.physics.p2.enable(ground); ground.body.static=true; player = this.add.sprite(350, this.world.height - 150, 'player'); this.physics.p2.enable(player, false); player.body.setCircle(22); player.body.fixedRotation = true; player.body.mass = 4; player.body.name = 'player'; enemy = this.add.sprite(350, this.world.height - 450, 'enemy'); this.physics.p2.enable(enemy, true); enemy.body.setCircle(22); enemy.body.fixedRotation = true; enemy.body.mass = 4; var playerCollisionGroup = this.physics.p2.createCollisionGroup(); var enemyCollisionGroup = this.physics.p2.createCollisionGroup(); var groundCollisionGroup = this.physics.p2.createCollisionGroup(); player.body.setCollisionGroup(playerCollisionGroup); enemy.body.setCollisionGroup(enemyCollisionGroup); ground.body.setCollisionGroup(groundCollisionGroup); player.body.collides(enemyCollisionGroup, this.destroyEnemy, this); enemy.body.collides(playerCollisionGroup); enemy.body.collides(groundCollisionGroup);
  14. Hey all! So i've been working on a topdown style game using the P2 physics system. I've really enjoyed working with Arcade physics, but needed to switch to P2 to utilize polygon body shapes and polyline world collision maps. I'm trying to implement a "pit" object and currently have things working as I'd like (collision-wise) with the player in the following setup: - The pit is an object with a polygonal body I define in tiled and import into the game. - The pit body shapes are set as sensors to disable default P2 collision behavior. - When the player contacts the "pit" shape its velocities are stopped and it enters a flail state on the edge of contact. - If the players flail timer runs out it will fall into the pit. What I'm having trouble with is figuring out how to determine the correct angle for the player to fall (into the pit) once the flail timer runs out. The player has 8 way movement and the pits are generally laid out as polygonal shapes with right angles. I looked around the boards and found talk of getting the centers of mass for the objects and calculate the vector angle between them and thought this might work, but can't seem to find a way to make it happen. I thought if I could get some point where the bodies/shapes collided I could jut calculate the angle between the player origin and the collision point, but can't find any way to actually get this point. Is this data available? Am I going about this completely wrong?
  15. Hello, I would like to know if it is possible to visually debug constraints when using P2JS (springs, revoluteconstraints, distanceconstraints, etc.) I found this image of box2d debug to illustrate what I mean Thanks in advance for any advice!
  16. Now I managed to get moving with mouse working. Now I am creating jumping, which is made by pressing left mouse button. How can I make my sprite to jump only ONCE, when left mouse button is clicked? I explain this kind of procedure: When you press left button of your mouse ONCE. I mean once when you press left mouse button with your index finger and then release it. LIke you clicked the link of this thread. When you click, sprite jumps ONCE and then falls back to floor. Not jump twice, not begin to flow on air. Just jumps once. Please, read this post once again before replying to this, so you fully understand my problem. Because I have seen too many threads on these forums where have been asked help i.e. for p2 physics, and somebody has answered with arcade physics code.
  17. I am making a spaceship game, to be more optimized I want to avoid calculing collisions when are far away from the player. I tried doing: 1) enemy.body.enable = false;2) Also this doesn't work. Because I never set it to true: enemy.body.data.shapes[0].sensor = false;3) Kill and revive them: it's not the best solution, because I want them to change positions. Nothing seems to work. What can I do? This is a part of my code for collisions in p2: this.body.setCollisionGroup(enemyCollisionGroup);this.body.collides([bulletCollisionGroup, playerCollisionGroup, enemyCollisionGroup, asteroidCollisionGroup], null );this.body.onBeginContact.add( this.startConstantDamage, this );this.body.onEndContact.add( this.endConstantDamage, this );Thanks
  18. Here's my question. I want to make a P2 body move in the direction it is already pointing. I tried moveUp(), moveDown(), etc. but they (not surprisingly) only go up or down. I tried thrust() but it does not seem to work unless it is being applied repeatedly.. as in the Update section. Just for the heck of it I tried this.... for (var i = 0; i < 500; i++) mysprite.body.thrust(500); and it did what I want, but I feel that this is probably not the way I should do this. Is there a better way? Thanks,Sam
  19. HI, I'm making a game with P2 Physic and I'm struggling with a little problem. I've created a polygon shape with PhysicsEditor and attached it to a sprite. The problem comes when I move my sprite to the left and change my orientation with: player.scale.x = - 1;The sprite flips but the shape stays the same. Do you know a way to also flip the P2 body? Thanks in advance.
  20. Hi everyone! It's my first post on this forum, but I'm for a longer time just reding posts. Ok, finally I have to ask a few questions by myself. If tl;dr, read just numbered questions (or one of them though) Actually I'm creating a fast-paced 2d shooter (side-scrolled, like soldat - if You don't know this game, take a look at video in the end of post) and finally got few problems. Game is using PIXI.js and uhm.. Was using p2.js, but that library has been superseded by PhysicsJS. Now I still have few problems, that is: 1. I still wonder if PhysicsJS is a good physics library for fast-paced shooter and I'm still thinking about return p2.js or use another better engine. I have read and checked few other libraries (like matterjs - box2d and similar aren't an option because of not plain javascript code). Is there any better option? 2. I have a problem with shooting. I really don't know how to do this. Or maybe otherwise - I have done it, but not the way I want. In p2.js everything is excellent except shooting - If bullets were too fast, collision detection event didn't notice collision beetwen bullet and other stuff. That's a major reason why I changed library to PhysicsJS. Now there is a problem with gravity and shooting. If Bullets are fast, they appear on screen in groups of 4 bullets separated by few pixels. Otherwise they are landing on ground very quickly. How can I do better shooting ? Maybe just in PIXi.js with own collision detection (just for bullets) function ? 3. This game will be a multiplayer. Is PhysicsJS or p2.js a good library to run on node.js? And will sharing few servers (game rooms) on one node.js server (for ex. 4-5 servers for 20 players one) be a good option looking at performance and cpu? Thanks a lot for reply ! As I said at beggining, I'm giving soldat gameplay:
  21. I have 2 bouncing balls which are bouncing off world borders and also off each other. The balls do maintain their speed when bouncing off the world borders but they lose their speed when bouncing off each other. I'd like them to maintain their speed after they collide with each other. I realise this is quite against the physics but is this doable? Here it the game implemented with p2 physics http://finspin.github.io/bubble-game/version-2/ and the code below. And here is the same game implemented with arcade engine where balls are bouncing without losing the speed http://finspin.github.io/bubble-game/version-1/. I switched from the arcade engine to p2 after I learned arcade can't handle collision of circular objects. var game = new Phaser.Game(480, 640, Phaser.AUTO, 'Bubble Game', { preload: preload, create: create, update: update, render: render});var b1, b2, bubble1, bubble2;function preload() {}function create() { game.stage.backgroundColor = "#000"; game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); var bubbleCollisionGroup = game.physics.p2.createCollisionGroup(); game.physics.p2.updateBoundsCollisionGroup(); b1 = game.add.graphics(); b1.beginFill(0xFF0000, 1); b1.drawCircle(0, 0, 50); bubble1 = game.add.sprite(game.world.width - 380, game.world.height - 50); bubble1.addChild(b1); bubble1.anchor.setTo(0.5, 0.5); b2 = game.add.graphics(); b2.beginFill(0xFFFFFF, 1); b2.drawCircle(0, 0, 50); bubble2 = game.add.sprite(game.world.width - 245, game.world.height - 50); bubble2.addChild(b2); bubble2.anchor.setTo(0.5, 0.5); bubbles = game.add.group(); bubbles.add(bubble1); bubbles.add(bubble2); game.physics.p2.enable(bubbles); bubbles.forEach(function (bubble) { bubble.body.setCircle(50); bubble.body.setCollisionGroup(bubbleCollisionGroup); bubble.body.collides([bubbleCollisionGroup, bubbleCollisionGroup]); }); var bubbleMaterial = game.physics.p2.createMaterial('bubbleMaterial'); var worldMaterial = game.physics.p2.createMaterial('worldMaterial'); bubble1.body.setMaterial(bubbleMaterial); bubble2.body.setMaterial(bubbleMaterial); game.physics.p2.setWorldMaterial(worldMaterial, true, true, true, true); var contactMaterial = game.physics.p2.createContactMaterial(bubbleMaterial, worldMaterial); contactMaterial.friction = 0; contactMaterial.restitution = 1.0; bubble1.body.damping = 0; bubble1.body.velocity.x = 200; bubble1.body.velocity.y = -200; bubble2.body.damping = 0; bubble2.body.velocity.x = -100; bubble2.body.velocity.y = 250;}function update() {}function render() {}
  22. How could I make ball bouncing off the world borders constantly? I tried to play around with contactMaterial properties but nothing seems to do the job. The ball will slowly lose its velocity. I'd like it to bounce constantly with constant velocity. var game = new Phaser.Game(480, 640, Phaser.AUTO, 'Bubble Game', { preload: preload, create: create, update: update, render: render});var bubble1;function preload() { game.load.image('bubble1', 'assets/bubble1.png');// game.load.image('bubble2', 'assets/bubble2.png');// game.load.image('bubble3', 'assets/bubble3.png');}function create() { game.stage.backgroundColor = "#000"; game.physics.startSystem(Phaser.Physics.P2JS); bubble1 = game.add.sprite(game.world.centerX, game.world.centerY, 'bubble1'); game.physics.p2.enable(bubble1); bubble1.body.setCircle(50); var bubbleMaterial = game.physics.p2.createMaterial('bubbleMaterial', bubble1.body); var worldMaterial = game.physics.p2.createMaterial('worldMaterial'); game.physics.p2.setWorldMaterial(worldMaterial, true, true, true, true); var contactMaterial = game.physics.p2.createContactMaterial(bubbleMaterial, worldMaterial); contactMaterial.friction = 0; contactMaterial.restitution = 1.0; contactMaterial.stiffness = 0; contactMaterial.relaxation = 0; contactMaterial.frictionStiffness = 0; contactMaterial.frictionRelaxation = 0; contactMaterial.surfaceVelocity = 0; bubble1.body.velocity.x = 200; bubble1.body.velocity.y = 200;}function update() {}function render() {}
  23. I'm using Phaser 2.4.2 with P2 physics. I have a sort of jar shaped body containing some circular bodies (balls). I want to move the jar offscreen but the balls are colliding with the world bounds. I tried setting collideWorldBounds on the balls but this stops them colliding with the jar which I want. You can see a demo here: https://output.jsbin.com/vuyexo Click the red button to make the jar move. Uncomment `collideWorldBounds=false` in the 'balls' section to see my problem. Why is this happening and how can I make the balls collide with the jar body but not the world bounds when the jar is moved offscreen?
  24. Hi guys. I've recently started to learn Phaser and i think it's pretty awesome but i have a little problem. I'm using P2 Physics. I have an image-based rectangle(1 img for vertical parts, 1 for horizontonal) and 2 circles in my game. One of the circles is player and other one is the ball. I wrote the player and ball collision parts successfully, but when i press SHIFT key(pressing shift means you hit the ball in my game and ball accelerates with speed 400) sometimes ball just ignores the walls and passes them. I spent all my day and night without sleep but i couldn't make it. Some help would be nice, take care of yourselves By the way, there is no player and wall collision so i seperated and used them as collisionGroups.
  25. Recently I am doing a project, in which I have to set a constant velocity value to a ball. This game is much like PingPong. I am now using P2 physics, but when test it on mobile, there are a big performance problem. On Android, the problem could be a small problem due to different browser, but it still remain somtimes, there is a little bit stutter when I playing. Because I don't have the things like vector, so I can not get or set it's magnetic efficiently, so I have to calculate the angel and value of the velocity and set it to constant values every frame, I think this might be the main problem. And I also want to know, if it's also because the P2 physics caused too much, I know that there are a box2d plugin in phaser, it costs a bit, but I want to know if my game's performance would become better if I change to box2D, what's the difference between box2d and p2. And I also want to know if anyone could have a better solution to due with the constant velocity problem, I need it to bounce, and if it's possible I also want to constraint the angle, because I don't want the ball to bounce like parallel to the bouncing board. Thanks a lot!