Jump to content

Search the Community

Showing results for tags 'P2 physics'.

  • 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 Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

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 18 results

  1. I came across a problem while the play again button is clicked. I have 3 states in my game. when the game is over, there is a button given to the user for playing again, that button leads the user to game state. I have used P2 physics. I am using sprite.id for collision detection, but while playing again the id changes every time. I tried using destroy() to delete the existing p2. But that gave me more errors while playing. How can i reset the Physics when playagain button is clicked? Hope someone can help in this?
  2. I'm trying to apply physics to a animated sprite. I used PhysicsEditor to generate the JSON and loaded the polygon shape for the first frame. Collision detection is not happening when i try to clear the shapes and load the polygon dynamically with respect to animation. Is there any method to clear and load the polygon dynamically to detect collision. Any thoughts ?
  3. Hi, I need help to resolve the overlapping of 2 physics object. So I have this ant that I want to drag then it must not overlap with the map(maze) here's the example: http://s3-ap-southeast-2.amazonaws.com/demos.wingaru.com.au/au.com.wingaru.honeyant_WK/index-dist.html#!/#%2F Edit* as you can see the ant can overlap with the map. Try to use keyboard arrows and it will not. Only when the ant is dragged. 'use strict'; Game.GameArea = { player: null, maps: null, mouseBody:null, mouseConstraint: null, create: function () { this.game.physics.startSystem(Phaser.Physics.P2JS); var level1 = [ ['layer6', 0, 0, 0], ['layer7', 393, 0, 0], ['layer8', 361, 239, 0], ['layer4', 0, 296, 0], ['layer3', 134, 242, 0], ['layer2', 296, 110, 0], ]; var antCollisionGroup = this.game.physics.p2.createCollisionGroup(); var mapCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.game.physics.p2.updateBoundsCollisionGroup(); this.maps = []; for (var i = level1.length - 1; i >= 0; i--) { var xpos = level1[i][1]; var ypos = level1[i][2] var map = this.game.add.sprite(xpos, ypos, level1[i][0]); this.game.physics.p2.enable(map); map.body.x += map.width / 2; map.body.y += map.height / 2; map.body.kinematic = true; //map is static map.body.clearShapes(); //Remove standard Bounding Box map.body.loadPolygon('collisions', level1[i][0]); this.maps.push(map); } //, , /*Adding ant*/ var antInfo = { xPos: 117, yPos: 163, rotation: 119.9998779296875 } this.player = new ant(this.game, antInfo.xPos, antInfo.yPos, antInfo.rotation); for(var m = 0; m < this.maps.length; m++){ var map = this.maps[m]; //set collision group map.body.setCollisionGroup(mapCollisionGroup); //set collision map.body.collides([mapCollisionGroup, antCollisionGroup]); } this.player.ant.body.setCollisionGroup(antCollisionGroup); this.player.ant.body.collides([antCollisionGroup, mapCollisionGroup]); //ENABLE DRAG this.mouseBody = new p2.Body(); this.game.physics.p2.world.addBody(this.mouseBody); this.game.input.onDown.add(this.click, this); this.game.input.onUp.add(this.release, this); this.game.input.addMoveCallback(this.move, this); }, update: function () { this.player.update(); }, click: function (pointer) { var bodies = this.game.physics.p2.hitTest(pointer.position, [this.player.ant.body]); // p2 uses different coordinate system, so convert the pointer position to p2's coordinate system var physicsPos = [this.game.physics.p2.pxmi(pointer.position.x), this.game.physics.p2.pxmi(pointer.position.y)]; if (bodies.length) { var clickedBody = bodies[0]; var localPointInBody = [0, 0]; // this function takes physicsPos and coverts it to the body's local coordinate system clickedBody.toLocalFrame(localPointInBody, physicsPos); // use a revoluteContraint to attach mouseBody to the clicked body this.mouseConstraint = this.game.physics.p2.createRevoluteConstraint(this.mouseBody, [0, 0], clickedBody, [this.game.physics.p2.mpxi(localPointInBody[0]), this.game.physics.p2.mpxi(localPointInBody[1])]); } }, release: function () { this.game.physics.p2.removeConstraint(this.mouseConstraint); }, move: function (pointer) { // p2 uses different coordinate system, so convert the pointer position to p2's coordinate system this.mouseBody.position[0] = this.game.physics.p2.pxmi(pointer.position.x); this.mouseBody.position[1] = this.game.physics.p2.pxmi(pointer.position.y); } //game.physics.p2.world.solver.iterations };
  4. Hello all, I have a problem with Phaser P2 physics in short i have 2 groups with objects. One is for my projectiles and the other is for enemies. The problem is that i want when projectile hits an enemy, the enemy should not move (it bounce back a little...). This is the code for my enemies i set the body.kinematic = true but it doesn't work. Thanks. this.enemiesGroup = this.add.group(); this.enemiesGroup.enableBody = true; for(var i = 0; i < 3; i++){ for(var j = 0; j < 9; j++){ var tmp = this.enemiesGroup.create( 80 +(j*66), y , 'enemies_1'); this.physics.p2.enable(tmp, this.Debug); tmp.enableBody = true; tmp.physicsBodyType = Phaser.Physics.P2JS; tmp.name = 'enemy' + buff; this.enemiesHP[tmp.name] = 100; tmp.anchor.setTo(0.3); tmp.angle = 90; tmp.scale.setTo(0.6); tmp.body.setCircle(18); tmp.body.kinematic = true; tmp.checkWorldBounds = true; var exp = this.enemyExplosion.create(0, 0, 'explosion'); exp.visible = false; exp.exists = false; exp.anchor.setTo(0.5); buff++; } y = y + 90; }
  5. Hey, I'm using p2 physics and I have a sprite (pixel line) that is rotating around some point (beginning of the line). For rotation I use angularVelocity. To display my sprite correctly I had to set it's anchor to (0,1) and it works fine, but collision box remained where it was before. Please check out my code and attached image game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); this.obstacle1CollisionGroup = this.game.physics.p2.createCollisionGroup(); this.obstacle = game.add.sprite(700, 400, "line"); this.physics.p2.enable(this.obstacle, true); this.obstacle.body.setCollisionGroup(this.obstacle1CollisionGroup); this.obstacle.anchor.setTo(0,1) this.obstacle.body.angularVelocity = 0.3; this.obstacle.body.angularDamping = 0;
  6. Hello, I was using Arcade physics and the collisions were working perfectly fine when defined as physics.arcade.collide. In my game, I have an AI character moving in a straight line, flipping direction when colliding with walls. Walls are defined in a layer, with a custom property 'collision' set to true. (defined in Tiled). I had to switch to P2 physics as I needed more sophisticated collisions for some objects that had polygon shapes, and also had to use something that P2.Spring defines. With P2, when my AI collides with the walls it bounces back in XY direction - while the ideal behaviour is that with - this.body.velocity.x *= -1; OR this.body.velocity.y *= -1; - It should only remain on its axis. I thought I would solve it by checking collision bodies in setPostBroadphaseCallback but that does not seem to work as desired or may be I am missing something very obvious. if(body1 != null && body1.sprite != null && body1.sprite.key === 'enemy'){ // I would want to check body2 as I do body1 but for my tile body2.sprite is NULL. } I even tried comparing with each wall body gotten from the below method - this.walls = this.game.physics.p2.convertTilemap(this.map, this.layers[layer.name]); The walls collision is defined as below - for(var i=0; i<this.walls.length; i++){ this.walls.setCollisionGroup(this.collision_groups["wallCG"]); this.walls.collides(this.collision_groups["playerCG"]); this.walls.collides(this.collision_groups["enemyCG"]); } Is there a way that I would know the collision group of body2? OR compare collision groups and not body1 and body2 in setPostBroadphaseCallback? Please help. It's urgent. Thanks in advance! agogiam
  7. Hello, It's my 2nd attempt to physics in game, first in P2. I want to create four lines in something like X shape and rotate it clockwise. Then I will be shooting some little balls and I would like to check if I hit my X obstacle - I do not want to destroy it, apply some gravity to it or more complex physics. On ball collision with my obstacle I just want to kill/destroy that ball. I don't want to move or destroy my obstacle. I've enabled physics at the beginning and created two collision groups game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); this.ballCollisionGroup = game.physics.p2.createCollisionGroup(); this.obstacleCollisionGroup = game.physics.p2.createCollisionGroup(); I'm spawning my obstacles consisting of 4 lines var dot = game.add.sprite(700, 350, "dot"); dot.anchor.setTo(0.5); this.obstacle.x = 700; this.obstacle.y = 350; var line = game.add.sprite(0, 0, "line"); line.anchor.setTo(0.5, 0); this.obstacle.addChild(line); var line2 = game.add.sprite(0, 0, "line"); line2.anchor.setTo(0.5, 0); line2.angle = 90; this.obstacle.addChild(line2); var line3 = game.add.sprite(0, 0, "line"); line3.anchor.setTo(0.5, 0); line3.angle = -90; this.obstacle.addChild(line3); var line4 = game.add.sprite(0, 0, "line"); line4.anchor.setTo(0.5, 0); line4.angle = 180; this.obstacle.addChild(line4); dot.bringToTop(); this.obstacle.physicsBodyType = Phaser.Physics.P2JS; this.obstacle.enableBody = true; for (var i = 0; i < this.obstacle.children.length; i++) { game.physics.enable(this.obstacle.children[i], Phaser.Physics.P2JS); this.obstacle.children[i].body.angularVelocity = 30; } and my ball this.ball = game.add.sprite(this.activeClock.x, this.activeClock.y, "ball"); this.ball.anchor.set(0.5); game.physics.enable(this.ball, Phaser.Physics.P2JS); this.ball.checkWorldBounds = true; this.ball.events.onOutOfBounds.add(function(){ game.state.start("Intro"); }); this.ballGroup.add(this.ball); this.ball.body.velocity = game.physics.arcade.velocityFromAngle(shootAngle, ballSpeed); this.ball.body.setCollisionGroup(this.ballCollisionGroup); this.ball.body.collides([this.obstacleCollisionGroup], this.ballCollision, this); Right now I'm stucked at spawning my obstacles, because they are spawned on top of eachother and they got hit at spawning and all fall down my game. How to make my obstacles not collide with themselves and apply no gravity to them? Previously I've tried using ARCADE physics but it didn't track the motion of my obstacles in collisions, so I had to change to P2. Thanks in advance for help
  8. Hi, first time posting. I'm currently trying to predict the angle the ball will take after collision in a pool game. I attached a screenshot of what I want to implement. The white line coming in front of the pool cue shows where the ball will collide and the angle it will take after collision. Im currently using P2 Physics but cannot figure out what I should use to draw the line and calculate the angle. I started trying to use a geometry line, but that only shows in Debug mode, and I tried a Sprite that's a long line that I can then mask, but that's not working either. Any help would be appreciated, this is my first time making an html5 game and first time using phaser. I've previously made games for Mobile using Corona SDK and I know how I would draw the line there, but can't find anything in Phaser. Thanks!
  9. Hi everyone, I'm working on a relatively small web game, and I'm starting to feel concerned about performance and whether I'll be able to continue building on the game with the rate that my performance is degrading. I'm currently using p2 physics in general with some calls to arcade physics for things like distanceBetween and angleBetween. All of the projectiles are in sprite groups. On my desktop, I generally run at 60 fps but drop to 40-50 when the map is scrolling on the first stage, and drop to 20-30 on the second stage. I've also tested on some laptops that seem to get closer to 40 in general. The UI is only working in Chrome right now, so all of my testing data is from running the game in Chrome. My concern is that neither stage map is really that large, the game window size is relatively small, and I don't have very many enemies or projectiles active on either map. I'm not really planning on mobile performance, but I wasn't expecting to run into performance issues on desktop browsers so quickly and with such a small game. Here's a link to the current version: https://damp-hamlet-9791.herokuapp.com/ Any feedback would be greatly appreciated. I enjoy working with Phaser a lot and would like to continue, but if I'm just going to run into performance issues I'm wondering if I should switch to another engine.
  10. Hi there, I am new to phaser and to test it out I am recreating the old SlimeSoccer Java-browser-game. (http://slimegames.eu/soccer/) I've implemented it with P2 physics and generally it is working pretty well. However I am having a difficulty with making the body of the "players" behave properly when colliding with the ball. So far I haven't found a way to create the semi circlular shape with phaser/P2? Is it correct that this is not possible - that it is either a full circle or a polygon? I have created a polygon with a lot of points to "simulate" the circular shape, but it doesn't work as intended. I've tried actually making circular bodies to test the physics and that works great, except they should be "cut in half". Does anyone have a clue to how to approach this? Thanks! Anders
  11. Hi, I'm new to phaser. I'm trying to make a very simple game where you must avoid collisions. I started with Arcade Physics and I managed to make everything I wanted easily. But then I added complex characters and I needed more than a rectangle body to have accurate collisions. So I switched to P2 Physics and found out how to set my character's body as a polygon : player = game.add.sprite(0, 0, 'character')game.physics.p2.enable(player, true)player.body.clearShapes()player.body.addPolygon({}, [[0, -50], [-50, 0], [0, 50], [50, 0]])Which results in That's pretty cool, but I can't create a polygon that will perfectly fit my character since it is automatically "centered", and because of the character's animation, he isn't centered in the sprite. So I looked for a way to set an offset to my player body's polygon. I saw that there were offset arguments on `addRectangle` and `addCircle`, but not on `addPolygon` (automatically computed). I also saw the `addShape` method which takes a `p2.Shape` as first argument (btw I didn't find any documentation on this class). I tryed to use it with a Phaser.Polygon, but it failed. Any idea ?
  12. Hi, I'm making a game where the player controls a Mars Rover from a top-down perspective. I'm using the WASD control scheme and I'm trying to make it so the rover moves like a car. If you aren't sure what I mean, imagine looking down at a car performing a K-turn and you might know what I mean. I got this to work with Arcade Physics, even got it to work with groups. Now I don't know how to get it to work with P2 Physics. Here is my code: function MovePlayer(player, cursors, game){ //Player Basic Movement Controls //WASD declerations might be making things slower fyi. var W = game.input.keyboard.addKey(Phaser.Keyboard.W); var Al = game.input.keyboard.addKey(Phaser.Keyboard.A); var S = game.input.keyboard.addKey(Phaser.Keyboard.S); var D = game.input.keyboard.addKey(Phaser.Keyboard.D); if (Al.isDown) { //player.body.rotateLeft(100); player.body.angularVelocity = -5; } else if (D.isDown) { //player.body.rotateRight(100); player.body.angularVelocity = 5; } else { player.body.setZeroRotation(); } if (W.isDown) { player.body.thrust(450); } else if (S.isDown) { player.body.reverse(300); } else { player.body.damping = 0.75; } if (player.body.velocity > 1.0) { player.body.velocity = 1.0; } }Right now the rover moves like it's in a slip'n'slide. Holding down forward and left or forward and right keys results in the rover spinning around in place. Imagine an object facing the center of a circle and just rotating around the center. Same thing using the reverse key. I don't know how to get it to work right. Any ideas?
  13. Hi all, I've just experienced some trouble with P2 physics. My game uses Newtonian gravity, which requires pretty good integration, and I get some huge errors by just using basic P2 methods (applyForce etc.). My guess is, this is an integration problem, since Newtonian gravity is notoriously hard to integrate numerically. I was considering some fixes, but does anyone know first what integration method does P2 use for its physics step, and if it is possible to change it to a more expensive and precise one? For example, could I do a leapfrog or a Runge-Kutta without editing the source code? I don't know where to find these methods either, I've tried searching the source code but didn't find it. Thanks!
  14. is it possible to change the type of material like if we want to make sprite a behave like iron, steel, wood, plastic or any other solid material type is it can be achived in p2 physics like this var rocket = game.add.sprite(4,2,'rocket'); rocket.density = 3.6; rocket.volume = 12; rocket.resistence = 12; rocket.friction = 23; and so on....! please it's very important
  15. hi , I am can't add drag event after i applied p2 physics to the sprite . I have write my code .So plz help me out . thanks //code Game.GameScreen = function () { };Game.GameScreen.prototype = { create:function () { this.backgroundLayer = configObj.game.add.group(); this.backgroundLayer.z = 0; this.backGround = configObj.game.add.tileSprite(0, 0, 640, 832, 'bg'); //background image this.backgroundLayer.add(this.backGround); this.Level1 = [1, 2, 0, 0, 0, 1, 0, 0]; this.Xpos = [50, 100, 50, 50, 100, 50, 100, 50]; this.Ypos = [100, 200,300, 350, 180, 280, 380, 480]; this.RowNumber = 4; this.ColNumber = 2; this.SetVariable(); }, SetVariable:function () { this.blockArray = []; this.enablePhysic(); this.createBlock(); }, enablePhysic : function(){ configObj.game.physics.startSystem(Phaser.Physics.P2JS); configObj.game.physics.p2.setImpactEvents(true); configObj.game.physics.p2.restitution = 0.8; this.playerCollisionGroup = configObj.game.physics.p2.createCollisionGroup(); this.pandaCollisionGroup = configObj.game.physics.p2.createCollisionGroup(); configObj.game.physics.p2.updateBoundsCollisionGroup(); }, createBlock : function(){ var mWidth,mHeight; var pandas = configObj.game.add.group(); pandas.enableBody = true; pandas.physicsBodyType = Phaser.Physics.P2JS; for(var i = 0 ; i < this.ColNumber ;i++ ){ this.blockArray = []; for(var j = 0; j < this.RowNumber ; j++){ var pos = j*this.ColNumber+i; if(this.Level1[pos] != 0){ this.image = 'block'+this.Level1[pos]; var panda = configObj.game.add.sprite( this.Xpos[pos], this.Ypos[pos], this.image); configObj.game.physics.p2.enable(panda,true); panda.body.moves = false panda.body.setRectangle(40, 40); panda.body.setCollisionGroup(this.pandaCollisionGroup); panda.body.collides([this.pandaCollisionGroup, this.playerCollisionGroup]); panda.inputEnabled = true; panda.input.enableDrag( true); } } } panda.body.collides(this.pandaCollisionGroup, this.hitPanda, this); }, hitPanda : function(){ console.log("in cooool"); }, update : function(){ } };
  16. Hello! I´m newbie in Phaser and game programming, And I want to make a open air artillery game. I want the characters to have a up and down movement as if it they were levitating and I was wondering what was the best way to do it with P2 since it will be a artillery game and i'd like to see the characters react to the physical impact of projectiles while levitating. Sorry for any misuse of english (not my native language) and thanks!
  17. Hello Is there anything like bounce in Arcade Physics.... in P2 Physics? I can simply bounce two objects on collision in Aracde, but I cannot generate something like that in P2! I've defined collisions, bodies.... but I cannot generate what I want. I can change velocity to simulate bouncing, but I cannot find collide direction to simulate it correctly! In my sample, I don't want to have any gravity and friction. Thanks a lot.
  18. Hey guys, is it possible that a p2 physics body collide/overlap with an arcade body ? Thanks Greets
×
×
  • Create New...