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

  1. Hi, yesterday i was struggling with rotation of an enemy. In my game you drive a spaceship and the enemies should rotate to your location in the nearest way (left or right), so they can follow you. This seems to be simple, but i find some problems in the rotation degrees. First i have to find the angle that the enemy should have, to point to my spaceship. I find two ways to do it. The first doesn't work: angle = game.physics.arcade.angleBetween( this , player ); // returns angles between something like 3.1 and -3.1// ( this = Enemy class )I don't know why. Maybe because i am using p2 physics and not arcade? The second works: angleRadians = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x);angle = Math.atan2(this.position.y - player.position.y, this.position.x - player.position.x) * 180 / Math.PI;// returns 180 to -180So i use that instead. Here I find something strange, the 0° angle in the Enemy is on Top. But, the 0° angle returned in the var angle is on the left. ( both ways in clockwise ) Finally i try doing something tricky like this, but doesn't work properly: if( this.body.angle+180 - angle-90 <= 180 && this.body.angle+180 - angle-90 >= 0 ){ this.body.angle += .6;}else{ this.body.angle -= .6;} May if I figure out why the degrees are different, i can get it work. Thanks!
  2. Hey there, my game consists of a player implemented with P2 and enemies implemented with Arcade physics (for better performance, since the AABB is sufficient for them). How can I detect collision between the Arcade bodies and the P2 body/bodies ? (The point is: I want the enemies to bounce away) OR: I've read in some other thread, that P2 offers AABB. I've searched the Phaser docs, but I didn't find anything helpful. Can you recommend a way to implement the described above only with P2, without affecting performance? Thank you guys in advance!
  3. flo71099

    Box2D vs P2

    Hi, I've a mobile game developed using phaser, P2 and CocoonJS Canvas+, but on an iphone4s, the framerate is around 20fps, no problem with iphone 5 and higher or any GalaxyS (from 40 to 70). I have more or less sixties sprites with physic. So my question is, would Box2d help me make it more performant ? Thanks
  4. What's the best way to get started with the p2 physics system (other than the examples)? For someone who knows the Arcade system pretty well, what are the main differences and things to consider when working with p2? Also, do you guys use any external tool to create polygons or work with this library? Thanks!
  5. https://phaser.io/sandbox/edit/tpauMNLC When i try to enable p2 physics for a sprite i get Uncaught TypeError: Cannot read property 'set' of undefined. for the object.anchor.set(0.5); of @method Phaser.Physics.P2#enableBody. Please check the link above. Also how do i go about debugging in Sandbox? I have tried putting breakpoints in VM#### but a new one starts everytime i refresh or change something so that didn't work.
  6. I'm creating a game with many types of tiles. Each tile type has different properties that I'm customizing: it's texture, layering, and collision. These are all determined separately. In the interest of making my P2 life easy, I have two tile groups, collision and no-collision. The tiles that collide with the player are placed in one and the others go into the other. The problem is, as I mentioned before, my game is pretty layering-intensive. As of right now I haven't found a way to have individuals tiles within a group have an index independent of their parent group's. This makes sense of course, especially when you're familiar with the Pixi renderer. That doesn't really solve my problem however. Does anyone know of a way in which I can keep my collision groups separate from my layering? I would love, love, love if Phaser 3 had some sort of Z-index setter as well- manipulating everything through bringToTop() is pretty difficult.
  7. Hi there I'm learning up on how P2 collision groups work and I have a question. It seems that if I have two collision groups, one for the player and one for platforms, to get the two to interact I have to write: this.ground.body.collides(playerCollisionGroup);this.player.body.collides(groundCollisionGroup);If I just use one of those statements the collisions don't work, I have to use both. This seems a little strange - if ground is set to collide with player, why do I also have to set the player to collide with ground? It seems a little redundant. Is there a reason it has to be bound twice? Rich is a heck of a lot smarter than me so I assume I'm just missing a very good reason for this Cheers!
  8. Hi, I have some strange behavior, I made 2 collision groups in p2, first have one member - player character, the second one have tiles loaded from json made by tiled. everything seems to work fine, tiles are 15x15 blocks with black background and on borders i have dotted and dashed blue lines. my character can walk on this tiles so collision works but when he is moving camera is shaking and if space between border dots is wider than my character can fall inside title. so I made a little experiment and add some black solid tiles and my character can pass them like it was background ar nothing was there. So I have no idea what is going one. please help
  9. Hi, Im trying to detect collision in p2 from one side (like jumping on top of something) its easy with arcade phisics, but p2 don't have such option, i think. So is there any way to implement this? if not than I was thinking about sticking another invisible body to a side of object and detect collision with that second object instead. But I dont know how to stick other object to first one and I've experimented with RevoluteConstraint to do it but it;s not what I intended. my code: var constraint = game.physics.p2.createRevoluteConstraint(arrow, [20, 5.5 ], arrowTop, [5.5,5.5]); constraint.collideConnected=false; constraint.setStiffness(600); constraint.update();but it behave like two objects on elastic rope so sometimes arrowTop if closer to arrow and sometimes its further . even if I set more stiffness it's bouncing. Is there way to stick two bodies like on glue instead of rope ?
  10. this is how the array that contains all the physicsbodies is created polyline_bodies = game.physics.p2.convertCollisionObjects(supermap,"polygons");i can then cycle over all bodies and flawlessly set collisiongroups, materials and so on.. but if i want to cycle through this array and kill the physics bodies in it for (i=0; i<polyline_bodies.length; i++){ polyline_bodies[i].destroy()}i get the following weird error: Uncaught TypeError: Cannot set property 'body' of nullc.Physics.P2.Body.destroy @ phaser.min.js:23level0.update @ game.js:616how can i destroy the bodies in there.. thank you !
  11. I'm trying to create a game that involves platforms I can jump through and land on top of. However, when I jump through a platform and land on it, I bounce on top of the platform. The bouncing has to do with the height I dropped from onto the platform. In order to do the jumpthrough platforms, I used the ideas from this thread, and modified them to work with my game. The actual code I'm using in the onPreSolve method is below: world.on('preSolve', function(presolve) { for (var i = 0; i < presolve.contactEquations.length; i++) { var c = presolve.contactEquations[i] var f = presolve.frictionEquations[i]; if (c.bodyA.shapes[0].collisionGroup == GROUND || c.bodyA.shapes[0].collisionGroup == PLATFORM) { var yAxis = p2.vec2.fromValues(0, 1); var y = p2.vec2.dot(c.normalA, yAxis); if (y >= 0){ // check for jumpthrough object // check if moving upwards c.enabled = false //disable contactEquation if (f) { f.enabled = false //disable frictionEquation (solves the stuckInPlatform problem) } if (c.bodyA.velocity[1] < 15 ){ // velocity < 15 - still inside the platform c.bodyA.velocity[1] -= 5; // course correction! } } } } });The only thing that seems like it might be causing the issue would be the course correction, though I wouldn't expect that code to be executed when I am falling and land on top of a platform, since this should check if it is moving upwards on contact. If this is a common problem, please point me to the thread where I can read more about this, because I wasn't able to find it through searches. I've attached a video showing the bouncing. It's more slight in the video than usual, but sometimes it gets to the point that the character is bouncing higher than he is tall. (I apologize for the poor video quality, don't have any screen recording software installed on this computer.) IMG_1733.MOV
  12. In the game that I am currently making using Phaser and P2 Physics I am looking to turn off the collisions between 3 objects when the game is paused or when the level has ended and the scoreboard shows so that unnecessary collisions are not being checked and dropping the frame rate (game is intended to run on mobile devices). I am using the following two functions at the moment TurnOffCollisions: function() { console.log("TurnOffCollisions") SavedBallVelX = Ball.body.velocity.x; SavedBallVelY = Ball.body.velocity.y; Ball.body.velocity.x = 0; Ball.body.velocity.y = 0; this.game.physics.p2.gravity.y = 0; FairwayHole.body.clearCollision(); Ball.body.clearCollision(); FairwayHole.body.clearShapes(); Ball.body.clearShapes(); Block.body.clearCollision(); Block.body.clearShapes(); },And to turn on the Collisions again when the game is unpaused or the next level starts: TurnOnCollisions: function() { console.log("TurnOnCollisions"); this.game.physics.p2.enable(FairwayHole); this.game.physics.p2.enable(Ball); this.game.physics.p2.enable(Block); FairwayHole.body.loadPolygon("Physics", "Level1-Hole"); FairwayHole.kinematic = true; Ball.body.loadPolygon("Physics", "Ball2"); Ball.body.velocity.x = SavedBallVelX; Ball.body.velocity.y = SavedBallVelY; Block.body.static = true; this.game.physics.p2.gravity.y = 1400; ballMaterial = this.game.physics.p2.createMaterial("ballMaterial", Ball.body); groundMaterial = this.game.physics.p2.createMaterial("groundMaterial", FairwayHole.body); this.game.physics.p2.setWorldMaterial(groundMaterial, true, true, true, true); contactMaterial = this.game.physics.p2.createContactMaterial(ballMaterial, groundMaterial); contactMaterial.friction = 0.5; contactMaterial.restitution = 0.5; }However when I do this it seems to work OK, until the Level Finishes and the Ball object and FairwayHole object are still touching, even though I think I have turned off the Physics I get the following error: Uncaught TypeError: Cannot read property 'collisionMask' of undefined54.c.runNarrowphasephaser.js:76867 54.c.internalStepphaser.js:76685 54.c.stepphaser.js:78255 c.Physics.P2.updatephaser.js:61785 c.Physics.updatephaser.js:26388 c.Game.updateLogicphaser.js:26327 c.Game.updatephaser.js:44881 c.RequestAnimationFrame.updateRAFphaser.js:44865 c.RequestAnimationFrame.start.window.requestAnimationFrame.forceSetTimeOut._onLoopIs there a better way of turning on and off collisions using P2 Physics? Or Am I doing something wrong with the way I am doing it that is causing the game to crash?
  13. When implementing collision with P2, I can't seem to get rid of a small bounce-back effect. Example: http://test.xapient.net/phaser/tilemapexample/index-p2.html In this example, when Mario jumps on the ground, it gets a little bit below the ground and then smoothly moves up quickly to stand on it. This doesn't happen with the Arcade physics and I can't seem to get rid of it with P2. Also every other example I've looked at has this effect and I tried several parameters. Since I only need AABB collisions, another approach I tried is implementing the collision myself in the update() routine. A very simple example for just a general ground would be:if (player.body.y >= 500) { player.body.y = 500; player.body.velocity.y = 0;}In this case, for one frame, the player appears below the ground. I assume this is, because this calculation would need to be done between the P2 physics calculations and the rendering, but the update() happens before the P2 physics calculations. Does anyone know how to around this bounce-back effect I'm describing? Cheers!
  14. it seems i cant even get an error message or a debug body.. it stays a rectangle.. trying with sprite.body.addCapsule(length,radius); thx for any tips!
  15. Hi everyone, I've got a problem about P2 body. I've got a group who contains sprites with body enabled. /*...*/this.game.physics.startSystem(Phaser.Physics.P2JS);/*...*/this.myGroup = new Phaser.Group(this.game);item = new Phaser.Sprite(this.game, x, y, 50, 'sprite');this.game.physics.p2.enable(item, true);this.myGroup.add(item);When I move the group like bellow this.myGroup.x = 100;this.myGroup.y = 100;Sprite move the right way, but not his body ! .. and that is my problem :/ what is the right way to make the body following the sprite ?
  16. I am trying to make a combat game. I want players to collide with the ground like normal, but to interact differently when they collide with other players. To do this, I've created a body with two shapes, one that is not a sensor, and collides with the ground, and one that is a sensor, and collides with other players. When I try to have both of the shapes active on the body, however, I fall through the ground. When only the ground colliding shape is active, the ground collision happens, but the other collision (obviously) does not happen. Is this a limitation in the p2 physics engine that doesn't allow a body to have shapes with different collision masks, or or do you think there is something I am doing wrong to mess this up? Below is the code I'm using to add the shapes to the body. I set the collision mask when I load the shapes earlier in the code. for (var i = 0; i < groundCollisionShapes.length; i++) { this.body.addShape(groundCollisionShapes[i], groundCollisionShapes[i].offset);}for (var i = 0; i < playerCollisionShapes.length; i++) { this.body.addShape(playerCollisionShapes[i], playerCollisionShapes[i].offset);}
  17. i'm (again) not able to remove ALL constraints in my game state by cycling through the array getConstraints should deliver because all entries are "undefined" am i doing it wrong? has something changed in 2.2.2 ??? thx for the help!
  18. The p2 docs are not of much help to me as I am not a physics academic. on the contactEquation I have this: function _onEnter(bodyB, shapeA, shapeB, contactEquations) { for(var i = 0; i < contactEquations.length; i++) { if(contactEquations[i].firstImpact === true) { window.console.log(contactEquations[i].relativeVelocity); } } } spr.body.onBeginContact.add(_onEnter, this);however, the contactEquations.relativeVelocity always returns 0, so I am looking for something else I believe. I need to play a sound when two objects collide, the volume will be dependant on either the relative velocity between these two objects, or even better, the total force they collide with, but I can calculate this myself with the velocities times the two bodies masses. The docs I am looking at: http://schteppe.github.io/p2.js/docs/classes/ContactEquation.html#property_contactPointA It seems like I may have to run some function to calculate the relativeVelocities, but I can't figure out which one as the docs only says something like: "Computes G*inv(M)*f, where M is the mass matrix with diagonal blocks for each body, and f are the forces on the bodies.", which does not make much sense to me. I really hope someone can help me out here I can't seem to find more documentation of p2 on my own.
  19. Hi! I want to import an object layer from Tiled map editor into a physics engine ( p2.js ). My problem is that p2.js uses 0.5,0.5 as anchor points, but tiled uses 0,0 (top-left). How can i recalculate it's position so i can give it the proper coordinated for a different anchor point? Any help is very much appreciated! Edit : This is easy with rectangles, but my problem is with rotated polygons.
  20. is there a way to disable collisions for a certain object but still get the onBeginContact event when they collide? activating sensor is no option because i need the object to still collide with everything else.. using collision groups seems not to work either because if i configure obj1 to not collide with obj2 the onBeginContact event is not fired anymore. for now i use a hacky workaround in the onPresolve Event to cancel the collsion response.. but i have the feeling that there is an easier way for that. thx in advance
  21. 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
  22. Hello, I've been trying to make ground collisions for my using sensors, which means I've been having to handle collisions with the ground myself. I tried a couple things, first, I tried simply setting the velocity to 0 once I landed on the platform, but I would continue to fall through the platform. What I'm trying now is setting the gravity scale to 0, and the vertical velocity to 0 when I hit the ground. Then, when I detect input that'll make me leave the ground, I set the gravity scale back to 1, and the velocity is set based on the input. The problem is that when I hit the ground and set the scale and vertical velocity 0, my velocity isn't 0. It's 26.xxxx, which I believe is the speed from one tick of the gravity force being applied. I don't understand why this is the case, since I 0 the velocity and set the gravity scale to 0, I don't think it would affect the gravity to make it non-zero. Is the physics gravity applied later, and the gravity scale not upgraded until later in the physics loop? All my changes are in my contact event handler, and I don't know where that is in the physics loop hierarchy. If there is a better way to do these ground collisions, please let me know. I want to be able to drop through the platforms as well as land on them, and this is the best way I can come up with to do that. Thanks!
  23. Hello, I'm trying to make a set of platforms in my game using the p2 physics engine. I'm using p2 on the backend, and phaser for the frontend. I have set up four platforms arranged in a column like this: ---------- ---------- x ---------- ---------- Note: The 'x' marks the center of the world. The issues I'm having is that the collisions work in one direction but not the other, for each of the four platforms. In one direction, the player correctly collides with the platform. In the other, the character gains a huge burst of speed and is shot through the platform. On the two bottom platforms, the player can fall down through the platform and get the speed burst, but not move upward through the platform. The top two platforms have the opposite issue, they shoot you upwards if you collide with them when jumping upwards, but you can properly stand on them. I think part of the issue might be where I've set the center of the map and the way I implemented the platforms. I made the map and the ground as a single physics body (maybe not a best practice but I'm really not sure), and the center of the map is what I marked as the position of the body. Each of the platforms is a polygon, and the body is marked as static. The reason I think the issue may be the body's position, is because when I move any of the platforms to the opposite side of the center, the effect of colliding with them matches the other platforms on that side of the center point. I have no idea what may be causing this, as I can't even find the p2 collision code. Any suggestions?
  24. I'm having problems with making a ladder in my 2d platformer game. Is there a way to allow my player to pass through my ladder sprite but still be able to detect collision. For example, my player should be able to walk back and forth through the ladder, but once they hit the up key, they should be able to climb the ladder. I have tried using clearShapes but that seems to remove any collision between player and the ladder even though my player can pass through it. I am using P2 phaser.
  25. Hey everyone, I've making a game with various enemies that are made from balls with various abilities. I'd like one of them to grow and shrink over time, and I'm using the P2 physics module. Changing the size of the displayed sprite is easy with sprite.scale.x/y but I'm not sure what the equivalent command is to update the sprite.shape which is used by the physics engine. So when I scale it, I end up with a large sprite but the original hit box. What is the correct way to handle this? Is it necessary to remove and recreate the shape each time I resize my object? -MoragX