Search the Community

Showing results for tags 'Physics'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Platform
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 668 results

  1. Hi all am use physics P2, but i want a little optimize. I do not want the real-physics for me is enough just intersection ( because in my game all objects it's sensor. what can be done? For start, i want decrease step in world, how - it's possible (im use typescript and can't change source)? - what more? or better override arcade physics (to add customize circle-separate?) Thanks
  2. I have a game with a player sprite that moves on top of platforms (like Mario). Right now it works with Arcade physics for the y-axis and tweens for the x values, so I can control the horizontal movements very precisely. All moves of the playersprite end on a 64x64 grid. So when a tween ends, the x value is always a multiple of 64. Now I want to implment the physics engine for the x-axis as well, but I'm having trouble to achieve the same grid-value thing as above. When the playersprite bounces into walls, i want it to move to the nearest 64x64 position (but looking natural, of course). I already tried using calculating the nearest 64x64 coordinate, maintaining the direction of the current movement and keeping the velocity at speed until the exact point is reached, but this ended up very messy, because sometimes the sprite moves over this point because of a high speed, and I have to set the sprite back, which looks really weird. Hope the above is clear. Basically I want movements to fixed coordinates, but WITH a physics engine. Any ideas how to achieve this?
  3. I'm doing some experimenting in Phaser (to say the least), trying to find a way to randomly generate maps. Now, I've got something of a "framework" worked out for this. My problem, however, is that although I can display a "wall" tile, I can't configure physics. Here's where I'm at - including a few ideas I've tried: create: function() { this.makeMap(); this.Tile(128, 64, true, true)); this.renderMap(); }, // This is actually a "class" and is used to define a single // tile on the game screen. It also defines blocked vs. non-blocked // tiles both for movement and sight Tile: function(x, y, moveBlock, sightBlock) { this.x = x; this.y = y; this.moveBlock = moveBlock; this.sightBlock = sightBlock; this.body = this; if (moveBlock == false) { this.image = 'floor'; } else if (moveBlock == true){ this.image = 'wall'; this.tile = game.add.sprite(this.x, this.y, this.image); /* This doesn't work: game.physics.enable(this.tile, Phaser.Physics.ARCADE); game.physics.arcade.collide(this.tile, this.player); */ } }, // "map" is an array, and this function creates floor tiles (32, 32) and feeds // them into the map array. However, they are NOT actually rendered at this // point makeMap: function() { for (var y = 0; y <; y+=32) { for (var x = 0; x <; x+=32) { this.Tile(x, y, false, false)); } } this.room1 = new this.Room(32, 64, 64, 64); this.room2 = new this.Room(128, 128, 64, 64); //this.createRoom(this.room1); //this.createRoom(this.room2); }, // This is where the tiles are actually rendered... renderMap: function() { for (var i = 0; i <;i++) { this.newtile = game.add.sprite([i].x,[i].y,[i].image); game.physics.enable(this.newtile, Phaser.Physics.ARCADE); this.newtile.body.immovable = true; /* this doesn't work: if ([i].image == 'wall') { game.physics.arcade.collide(this.newtile, this.player); }*/ console.log([i].image); // for debugging } },As always, your help is greatly appreciated
  4. I want the player and the map layer collide, it should be like this: sometimes it goes well, but sometimes it appears like this: yet I know maybe it's cause by the high gravity(8000), but I have to keep it high because when it jumps, it falls too slowly. However, I don't understand why they won't collide since I coded:, this.layer);Here are my source code: Game.Play.prototype = { create: function () {; this.faceLeft = true; for(var i=0; i<28; i++){ for(var j=0; j<12; j++){*i, 60*j, 'wall');} } ='level_1',600,600);'collection_1'); // Preloaded tileset'player'); // Preloaded tileset this.layer =; this.layer.resizeWorld();,100,true); this.player =*19, 60*10-90, 'player', 18); this.movePlat =*13, 60*4, 'movePlat', 2) this.stopLAnim = this.player.animations.add('stopL', [0,1,2,3,4,5], 20, true); this.stopRAnim = this.player.animations.add('stopR', [6,7,8,9,10,11], 20, true); this.moveLAnim = this.player.animations.add('left', [12,13,14], 20, true); this.moveRAnim = this.player.animations.add('right', [15,16,17], 20, true); [this.player, this.layer, this.movePlat], Phaser.Physics.ARCADE); this.player.body.collideWorldBounds = true; this.player.body.gravity.y = 9000; this.cursor =;; this.movePlat.body.immovable = true; //movePlat tween this.tween ={ x: 60*17 }, 2000, Phaser.Easing.Linear.None) .to({ x:60*13 }, 2000, Phaser.Easing.Linear.None) .loop() .start(); }, update: function() {, this.layer);, this.movePlat); this.player.body.velocity.set(0); if (this.cursor.left.isDown) { this.player.body.velocity.x = -300;'left'); this.faceLeft = true; } else if (this.cursor.right.isDown) { this.player.body.velocity.x = 300;'right'); this.faceLeft = false; } else { if(this.faceLeft)'stopL'); else'stopR'); } if (this.cursor.up.isDown && this.player.body.blocked.down){ this.player.body.velocity.y = -2000; } if (this.cursor.up.isDown && this.player.body.blocked.down) { this.player.body.velocity.y = -600; //if (sound); this.playerJumpCount = 1; } else if (this.cursor.up.isDown && this.playerJumpCount < 18 && this.playerJumpCount != 0) { this.playerJumpCount += 1; this.player.body.velocity.y = -650; } else this.playerJumpCount = 0; //if(this.player.body.blocked.down) this.player.body.gravity.y = 100; //else {this.player.body.gravity.y = 6000;} },};Please help me! Thank you!!!
  5. I'm trying out the P2 physics engine, but I'm thinking I only need physics enabled for the y-axis. For example, a car-sprite that moves from left to right on a bumpy road. I would like the car to bounce up and down, when there's a bump in the road, but it needs to maintain a constant horizontal movement, and no weird collisions that make the car move left or or extra to the right. Is this possible with P2, or should I use Arcade physics (or maybe no physics engine after all) ?
  6. - Can you help this material shifting ball reach it's goal? Switch between materials , Get shot by a canon , Blown by a fan or Attracted by a magnet. It's an enjoyable journey! Preview on: Play now: This game is available for non-exclusive licensing.
  7. In my game I have a player, and I have several collision boxes, I want to know how to run a collision check on the box i'm closest to, or how to run them individually. My code: var player = { x:32, y:32, size:32, grav:0, xspeed:0, terminalVel:10, onGround:false, friction:0.8, update:function() { if (this.onGround == true) { this.grav = 0; } else if (this.onGround == false) { this.grav += 0.4; } if (this.xspeed > this.terminalVel) { this.xpseed = this.terminalVel; } if (this.grav > this.terminalVel) { this.grav = this.terminalVel; } this.xspeed *= this.friction; this.x += this.xspeed; this.y += this.grav; // Collision for (var key in boxes) { // Vertical if ((this.y+this.grav >= boxes[key].y-32 && this.y <= boxes[key].y) && (this.x <= boxes[key].x+boxes[key].width)) { this.onGround = true; this.y = boxes[key].y-32; } else { this.onGround = false; } } }};function basicBox(x,y,width,height,color) { this.color = color; this.x = x; this.y = y; this.width = width; this.height = height; this.draw = function() { g.fillStyle = this.color; g.fillRect(this.x,this.y,this.width,this.height); }}var boxes = [ new basicBox(32,128,32,32,"blue"), new basicBox(64,256,32,64,"orange"), new basicBox(256,32,128,64,"red"),];function run() { // game loop for (var key in boxes) { boxes[key].draw(); } player.update();}I am pretty new to javascript, so how would I go about doing this?
  8. Hello! I've been trying to get Oimo working, and all I've managed to do is a very basic imposter and compound imposter. My question is... what does Babylon support for Oimo at the moment? joints? motors? I can't seem to find any documentation on this, and would be grateful for answers. :3 Thanks! EDIT: Also, is it possible to have collisions without having physics? Thanks again!
  9. Hello, I'm trying to extend the game build in a tutorial this one. I'm just trying to insert the baddie to run from one side to another, but the little thing insists in bug out, and "fly" around... I'm uploading the game.js file with all content. (As soon as someone explains to me how exactly can I do it... It says I cannot upload 'this kind of file' (tried rar and js)) I can't thank enough if someone can review my code, and find the error(s). Regards
  10. Hello! I'm still beginner in game programming, and I have headache right now because of physics with sprite groups. I know how to make sprite with P2 physics, and how to make them kinematic. But what I'm trying right now is to make group with same settings, and after couple of hours today, couple of tutorials I have no idea how to make it proper way. grounds =; // Create a group grounds.enableBody = true;grounds.physicsBodyType = Phaser.Physics.ARCADE; grounds.kinematic = true;This code don't collide with player (arcade/p2js) grounds =; // Create a group grounds.enableBody = true;grounds.physicsBodyType = Phaser.Physics.P2JS;grounds.kinematic = true;This could collide, but "grounds" aren't kinematic. Can someone help me? I have no idea.
  11. I've added a body that should have gravity to my game, so picture a big empty screen with a circle for "Earth" in the middle. Now when other bodies are added to the field, like an asteroid, I want them to be "attracted" to Earth, but not just immediately travel in a straight line to it. What methods would let me have any other body added to the game be "accelerated" or "attracted" to Earth? X-Post from StackOverflow, since this is a Phaser.js specific question.
  12. So I decided to use Arcade physics for my game and it seemed like it had some really awesome features. One of the problems I encountered though was that for the arcade system to be fully functinoal, it seemed like I had to use velocity to make movements, rather than just assigning the X and Y. This wans't a problem and I quickly adjusted. Now the problem came today, when another player was supposed to test the game. Her computer didn't handle it as well and that's when I realized that velocity is based on how much time each update takes. This is a huge problem because this meant that on a lower-end machine the player would sometimes drop through the floor! This game is supposed to be used at an event, so that's REALLY unfortunate. Is there ANY way I can change this? So velocity always assumes a certain amount of time passed between each frame?
  13. I have a game where a player-sprite can jump on top of blocks. These blocks are moving vertically up and down (with a tween). Arcade physics and gravity is enabled on the player-sprite only. But sometimes the player-sprite falls 'through' a block, as if the physics engine of the player can not calculate correctly if there's a block underneath the player. Can anybody tell me why this is happening, and how to prevent this ?
  14. Good Evening, In my little project, I have a tile that blinks - when it is "on", it will player.kill(). However, when it is "off" the player can pass by unharmed. Now, here's the problem: when the player passes by, there seems to be some delay, so that even though the player is not longer in the blink-tile's space, it will player.kill(). I'm not sure why this is happening, but it's very frustrating for my alpha testers - my kids Here's my relevant code: function update() { game.physics.arcade.collide(this.player, this.burn, death, null, this);}function death() { this.player.kill();}As always, your help is greatly appreciated - overall, I've been very impressed with the Phaser community so far! Thanks
  15. Hello Babylon.js forum! I'm developing a coin pusher type game as a foray into 3D game dev. But I'm stumped on something. I put an animation on the pusher var sliderBox = BABYLON.Mesh.CreateBox("slider_box", 2, scene);sliderBox.scaling = new BABYLON.Vector3(2.5, 0.2, 1.5);var sliderZPos = { allIn: backWallBox.position.z, allOut: backWallBox.position.z - sliderBox.scaling.z * 2 }; sliderBox.position = new BABYLON.Vector3(0, 0.2, sliderZPos.allIn); // Slider animation var sliderAnimation = new BABYLON.Animation("slider_animation", "position.z", 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); var keys = [ { frame: 0, value: sliderZPos.allIn }, { frame: 90, value: sliderZPos.allOut }, { frame: 180, value: sliderZPos.allIn }, ]; sliderAnimation.setKeys(keys); sliderBox.animations.push(sliderAnimation); scene.beginAnimation(sliderBox, 0, 180, true, 1); This works great, but I need to enable physics on it and this disables the animation. Physics code is simply... sliderBox.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, move: false});I do not understand 3D development enough to figure this one out, I've done Google searches but haven't found a solution. How can I emulate what an animation would do with physics? Or am I doing something wrong with regards the animation and/or physics code. Extra info: the rest of the code is standard stuff and I'm using oimo.js for physics. Any help is greatly appreicated. Thanks
  16. Descensus is a simple 2D physics game which I've described as somewhere between a marble roll, tennis, and Tetris. Teris in the sense that gravity increases over time and you have to guide your object as it falls. It's built with my P2Pixi JavaScript framework: which is itself built around the excellent libraries p2.js (for physics) and PIXI (for WebGL rendering). It's packaged for Android using CocoonJS, which I have found to be by far the best of its bunch. I hope to also release it for iOS. It also works perfectly as an online game (though using a mouse rather than touch isn't as fun), although I haven't made it available online yet and I'm undecided if I will. Enjoy!
  17. Hi All - I have two Sprites, a player and a shape. When the player is overlapping the shape, I want it to accerate the player sprite object (like a conveyor belt).. I'm having some issues getting this to work with the following code: var Player = function(game, x, y, frame) {, game, x, y, 'playerMovements', 0);; this.body.collideWorldBounds = true this.anchor.setTo(0.5, 0.5);}; var Belt = function(game, player, x, y) { var beltBMD = game.add.bitmapData(50, 400); beltBMD.ctx.fillStyle = 'red'; beltBMD.ctx.fillRect(0, 0, 50, 400);, game, x, y, beltBMD);; // Code that isn't working as intended, player, this.applyEffect, null, this);, this.destroy, this);; player.bringToTop()}; Belt.prototype.applyEffect = function(drop, player) { console.log(drop.body.overlapX); // 0 console.log(drop.body.overlapY); // 0 console.log(player.body.overlapX); // 0 console.log(player.body.overlapY); // 0 player.body.velocity.y += 400;}; The issue is that my applyEffect callback gets triggered, but there isn't an overlap property set on either of the two objects so I can't accelerate until the overlap properties are back to 0 because they never seem to be set in the first place. If the callback gets triggered, shouldn't an overlap be set? Open to other suggestions about how to do this, I went with the bitmap data approach because I need to be able to draw shapes w/ physics bodies which the Graphics class doesn't support. Thanks!
  18. For some reason, Mario will just fall through the tilemap layer "Ground". Do I have the collision and physics set up correctly? I used the Starstruck example on the Phaser website, but to no avail. Thanks in advance guys!var game = new Phaser.Game(320, 240, Phaser.AUTO, 'gameCanvas');var map;var tileset;var groundLayer;var mario;var cursorsvar playState = { preload: function() { game.load.tilemap('level01', 'assets/level01.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles1', 'assets/mariotileset.png'); game.load.spritesheet('marioSheet', 'assets/marioSheet.png', 16, 25); }, create: function() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#66DDFF'; map = game.add.tilemap('level01'); map.addTilesetImage('tileset', 'tiles1'); map.setCollisionBetween(136, 140); groundLayer = map.createLayer('Ground'); groundLayer.resizeWorld(); game.physics.arcade.gravity.y = 350; mario = game.add.sprite(200, 200, 'marioSheet'); game.physics.enable(mario, Phaser.Physics.ARCADE); mario.body.collideWorldBounds = true; mario.anchor.setTo(0.5, 1); mario.animations.add('walk', [0, 1, 2, 1], 15, true); cursors = game.input.keyboard.createCursorKeys(); }, update: function() { game.physics.arcade.collide(mario, groundLayer); mario.body.velocity.x = 0; if (cursors.left.isDown) {'walk'); mario.scale.x = -1; mario.body.velocity.x = -200; } else if (cursors.right.isDown) {'walk'); mario.scale.x = 1; mario.body.velocity.x = 200; } else { mario.animations.stop(); } }};game.state.add('play', playState);game.state.start('play');
  19. I am experimenting with loading in 3D models from another program and applying physics to them. I've been using MeshImpostor, but not getting the results I expect. For example: I expect that the balls would stay inside of the "cup", but they go right through the sides. Plus, if you watch closely, occasionally, the balls will bounce off of nothing or fall through the middle. The model was created in Maya, exported to OBJ, and converted to babylon using the online converter. Is there a problem with how the model was prepared? Should I be doing something different? Thanks!
  20. Hi, I just creating pinball game with Phaser... I'm using P2 physics. I have one sprite BALL: this.ball = game.add.sprite(x, y, 'ball'); game.physics.p2.enable(this.ball, false); this.ball.body.setCircle(10); this.ball.body.fixedRotation = true;But in one case I need to make this ball to ignore collisions with all elements... (ball should to pass through other sprites without collisions) I just need to turn off gravity, collision and then randomly move ball to different place and then turn gravity/collisions ON. I'm trying to create ball movement in rails above other elements.
  21. Hi guys, I'm trying to make a conveyor belt in contact with which the hero would begin to roll var mat1 = game.physics.p2.createMaterial('hero_material', hero_b.body);var mat2 = game.physics.p2.createMaterial('transp_material', obj.body);var contactMaterial = game.physics.p2.createContactMaterial(mat1, mat2);contactMaterial.surfaceVelocity = 100;;I wrote this code but it does not work, please help to understand what I'm doing wrong. Cheers
  22. Hey everybody, I'm looking for a way to check if a sprites encounters another sprite on a given trajectory BEFORE it evens starts moving. That's because if the sprite will collide with an another one while moving in that direction I don't even want it to go. Can somebody please explain to me how can I accomplish that? Thank you in advance!
  23. I have a game where the screen fills up with falling blocks in a grid. The blocks are rendered by canvas drawing operations and use arcade physics to test for collisions between the blocks-group and itself, and the the ground. The game runs fine at 60fps on desktop, and it also runs fine on mobile -- until I get about 20 blocks on screen. Then the framerate drops progressively, down to about 30fps when the screen is filled with blocks. I have done some profiling and debugging and believe the problem is with the physics quadtree operations. In the profiler, before many blocks stack up, the rendering functions take most of the time. After a few blocks get stacked up, the heavy operations are all quadtree related. See the attached screenshots (profile1 and profile2 respectively). I have tested rendering simple sprite images instead of canvas drawings, with no difference. I have tried to disable physics on blocks once they land, but only partially succeeded (this.body.enable = false). I tried switching landed blocks to a different group, but had other problems with that and gave up. Should that even be necessary? All my code is at You can test the game yourself at Any suggestions on what I am doing wrong, or if I need to be more clever at something? Thank you so much for your help - I'm new to Phaser, but I really like it, and want it to work for me, but it's got to work on mobile. Everyone tells me to just use Unity, but I want to give this a try.
  24. Sup guys, Here's another our game - "Haunted Halloween" It's a physics puzzle game. We used Box2d and our own framework. The old scatterbrain skeleton has lost his head and the player's task is to return the head to its owner. You can move platforms, make things explode and also change the sizes of some objects. And overcome some obstacles like dead hands. Here's a link If you have any questions please feel free to ask
  25. Before creating an issue on github, decided to put it here (as suggested here Class: Phaser.Physics.P2 Method: constructor Issue: physics config's user-defined options (mpx, mpxi, pxm, pxmi) get deleted in Phaser.Physics.P2 constructor. Proof: Why: game class instance passes the physics config to Phaser.Physics instance, then the config gets passed to Phaser.Physics.P2. Within this chain no other props are created, as a result 'broadphase' prop is never present in the physics config and always created by the p2 class. So, when a new p2 instace is created, the config with your custom mpx, mpxi, pxm, pxmi props gets replaced with a new config of { gravity, broadphase } only. As a result p2 uses default mpx, mpxi, pxm, pxmi methods (so they don't get overriden) How-to-fix: switch from config replacement to property adding. Current code: Phaser.Physics.P2 = function (game, config) {/** * @property {Phaser.Game} game - Local reference to game. */ = game;// @note// what if i already defined 'gravity' and 'broadphase' is not defined (btw it's never defined until this point)// my gravity prop will be also overridenif (typeof config === 'undefined' || !config.hasOwnProperty('gravity') || !config.hasOwnProperty('broadphase')){ config = { gravity: [0, 0], broadphase: new p2.SAPBroadphase() };}The fix: Phaser.Physics.P2 = function (game, config) {/** * @property {Phaser.Game} game - Local reference to game. */ = game;// config exists? if not - create oneif (typeof config === 'undefined'){ config = {};}// we got gravity? if not - define [0,0]if (!config.hasOwnProperty('gravity')){ config.gravity = [0, 0];}// we got broadphase? if not - create a new instanceif (!config.hasOwnProperty('broadphase')){ config.broadphase = new p2.SAPBroadphase();}// ... now mpx, mpxi, pxm, pxmi props will override the default methods properly// Pixel to meter function overridesif (config.hasOwnProperty('mpx') && config.hasOwnProperty('pxm') && config.hasOwnProperty('mpxi') && config.hasOwnProperty('pxmi')){ this.mpx = config.mpx; this.mpxi = config.mpxi; this.pxm = config.pxm; this.pxmi = config.pxmi;}