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


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





Found 661 results

  1. After merging 2 meshes trying to call applyImpulse results in a null exception something like this: Uncaught TypeError: Cannot read property 'applyImpulse' of undefined at CannonJSPlugin.applyImpulse (es6.js:81725) at PhysicsImpostor.applyImpulse (es6.js:80780) Same happens with Oimo. Replicated here:
  2. Her is an example based on a Phaser 2 example, 0 index is set as colliding: Her is the tiled json file: Phaser 2 example where empty (index 0 in tiled json) is not collideable: What is the easiest way to fix this in phaser 3? Setting 0 in setCollisionByExclusion method does not exclude it from collision.
  3. Hi everyone, I'm trying to figure out how to 'reset/readjust' a sprites collider after adjusting the sprites scale. The initial collider setup ( size/offset) is working perfectly at scale 1, with the following : sprite.setSize(44,64,true); sprite.body.offset.y = 44; scaling works great for both sprite and collider with : sprite.setScale(2); the issue is when i set the scale ( to 2 in this example ), the collider now has an offset. is there a built in way to 'reset' this collider so it aligns with the sprite? thanks for your help. var config = { parent: 'container', type: Phaser.WEBGL, width: 300, height: 300, parent: 'phaser-example', physics: { default: 'arcade', arcade: { debug: true } }, scene: { preload: preload, create: create } }; let game = new Phaser.Game(config); let sprite; function preload () { this.load.image('00', '00.png'); } function create () { sprite = this.physics.add.image(400, 300, '00'); sprite.setSize(44,64,true); sprite.body.offset.y = 44; sprite.setScale(2); sprite.setVelocity(100, 200).setBounce(1, 1).setCollideWorldBounds(true).setGravityY(200); }
  4. Does anyone know how I can get the Matter physics engine to render its geometry when running within Phaser? I.e. when I'm not assigning a sprite to a physics body, but I want the geometry of the objects I've created to be rendered as lines instead. If I set "debug" to true on the Matter config, I can see purple lines being rendered by the debugger. But if I set debug to false, I no longer see anything rendered. I've found there are a bunch of properties on the Matter "Body" object like StrokeStyle, LineWidth and FillStyle (described here) which seem designed for this purpose. However, I can't see equivalents for those in the Phaser documentation, and when I set the properties on the Matter body directly they seem to have no effect. Am I missing some simple piece of config or setup that I need to do, or have I stumbled across a bug or unsupported feature?
  5. Hello, I am making a kind of flappy bird. I want the pipes to move only horizontally. They have physics, so i can use the setVelocityX method. But they are falling down because of the gravity. I can change the position changing the x value of the pipe in the update method, but i would like to use the setVelocityX, it is more clear. var columna =; ... columna.setVelocityX(-200); Thanks!
  6. Hey there, I am still struggling a lot with Phaser3 due to the documentation is still in work. I made two simple sprites, that collide, what I experience is that >body.blocked.down< nor the other properties (left, right, top) ever change. They are always: false. No matter if a collision happens or not. A bit of code: //These are the arcade configs: physics: { default: 'arcade', arcade: { gravity: {x: 0, y: 2000}, debug: true, overlapBias: 20 } } //TileA this.plat = this.physics.add.sprite(400, 1100, 'platform'); this.plat.displayWidth = 500; this.plat.body.allowGravity = false; this.plat.body.immovable = true; //TileB is a custom class which just extends this.physics.add.sprite this.minion = new tileB(this, 500, 200); //collision works well with:, this.minion); However, the body.blocked property is logged in my update of the custom (tileB) class - and it is always false. No matter if it's colliding. Here is the code of the tileB class: class tileB extends Phaser.Physics.Arcade.Sprite { constructor(config) { super(config.scene, config.x, config.y, 'minion');; this.scene.add.existing(this); this.scene.layers.minions.add(this); this.controls = this.scene.input.keyboard.createCursorKeys(); //write controls class this.alive = true; this.body.maxVelocity.y = 1500; this.body.setSize(50, 100, false); this.body.setOffset(80, 60);'update', this.update, this); } update() { if( { console.log(this.body.blocked.down) if (this.controls.left.isDown) { this.setVelocityX(-200);'left', true); } else if (this.controls.right.isDown) { this.setVelocityX(200);'right', true); } else { this.setVelocityX(0);'turn'); } if (this.controls.up.isDown && this.body.blocked.down) { this.setVelocityY(-200); } } } } I have looked into the super mario example by @nkholski as he used body.blocked.down too. I had a hard time to find the point I am missing. Would be glad if someone helped me out nkholski's platformer boilerplate: Thanks in advance
  7. Hello everyone, I have the same problem like in this topic I don't understand how to set P2 Physic mode or solve this problem in other way. Please help.
  8. The PG is based on the PhysicsEngine HowTo example but modified to use instances. It seems to work with the gravitationalField but not applyRadialExplosionImpulse. Is there something I've missed or is this not possible right now?
  9. I'm trying to create platforms for my player to jump onto and also make collectible stars. I can create these sprites using functions, but I don't know how to make physics work on them so that the character can jump on the platforms and overlap with the stars. The problem is that the physics portion doesn't work when I call it in the update function. I am also not using tilesprites, so it can't work that way. create: function() { addStar(star1); }, update: function() { removeStar(star1); } addStar(name) { name = game.add.sprite(1700, 550, 'star'); name.anchor.setTo(0.5, 0.5);, Phaser.Physics.ARCADE); name.body.collideWorldBounds = false; name.enableBody = true; name.body.immovable = true; } removeStar(name) { if (game.physics.arcade.overlap(character, name) == true) { name.destroy(); updateScore(); } }
  10. Hi, I have this basic platform game and I would like the hero to jump through the platforms, from underneath to the top of the platform, but I´m not being able to do that and the head of the hero collides with the bottom of the platform even when I set the collideDown of that tile (actually, to all the tiles of that layer) to false. What am I missing? this.platformsLayer ="platforms"),50, true, "platforms") var tilesArray = this.platformsLayer.getTiles(0,0,, for(var i=0;i<tilesArray.length;i++){ tilesArray[i].collideDown=false tilesArray[i].setCollision(true, true, true, false) console.log("All set to false") }
  11. I'm doing P2 physics collisions with: sprite.body.collides(collisionGroups, callback, this); and I'm trying to get some info on the momentum transfer of the collision to calculate damage, but I can't find the right values. What I've tried is to use the velocity difference like this: var impactSquare = Math.pow(p2BodyA.velocity.x - p2BodyB.velocity.x, 2) + Math.pow(p2BodyA.velocity.y - p2BodyB.velocity.y, 2); This works ok, but obviously it gives totally wrong values when the bodies fly towards each other and just barely touch, then deltaV is pretty high but there is basically no momentum transfer. Since there is no V_old and V_new (as far as I know) to get the change of velocity per sprite (pre and post collision) I've tried to look into using the deltaX values: dx = sprite.previousPosition.x - sprite.position.x ... but stopped there because it feels like an over-complicated and unreliable way to get something that should be somewhere in the data anyway Has anybody an idea where to look? Another (likely over-complicated) idea was to use the onBeginContact method to get the pre-collision velocity and store that somewhere so we can call it in the collides feedback, but ... well feels like there must be something simpler ...
  12. Is there a way to create a text object with physics on it, the same way I'm able to create an image object, like this:, scene, 0, 0, "my_image"); If there isn't a direct way of creating such thing, what would be a good alternative of having a dynamically generated text that acts like a game object with physics?
  13. I've played around with P2 physics and created a sprite that has a child attached that can (is supposed to) move freely around the parent. The child should still contribute to collisions with other objects so I gave it a P2 body as well, but it was behaving very odd. A closer look at the debug data revealed that the collision shape and the sprite image are not at the same position o_O in fact the collision shape is located at an absolute position in the world that relates to the relative coordinates between parent and child and does not move at all. Here is an example that you can try with the sandbox editor: game.physics.startSystem(Phaser.Physics.P2JS); var parent = game.add.sprite(200, 200, 'phaser'); game.physics.p2.enable(parent, true); parent.anchor.set(0.5); var child = game.make.sprite(100, 100, 'phaser'); game.physics.p2.enable(child, true); child.body.static = true; child.anchor.set(0.5); child.angle = 0; parent.addChild(child); If you look at the attached image you can see the offset. When dragging the parent around with the mouse the collision shape will stay at a fixed position, but it CAN collide with the parent. This issue might be related to an older discussion: Any ideas how we can fix this (that don't involve creating the child as a "free" sprite and let it follow the parent via the update() function)?
  14. <!DOCTYPE html> <html> <head> <script src='./node_modules/babylonjs/dist/preview release/babylon.js'></script> <script src='./node_modules/babylonjs/dist/preview release/cannon.js'></script> <script> document.addEventListener('DOMContentLoaded', () => { const canvas = document.getElementById('renderCanvas') const engine = new BABYLON.Engine(canvas) const scene = new BABYLON.Scene(engine) scene.enablePhysics() const physicsHelper = new BABYLON.PhysicsHelper(scene) const camera = new BABYLON.ArcRotateCamera('camera', 1, 20, 10, new BABYLON.Vector3(20, 0, 0)) camera.setPosition(new BABYLON.Vector3(0, 20, -30)) scene.activeCamera.attachControl(canvas) const sun = new BABYLON.HemisphericLight('', new BABYLON.Vector3(0, 1, 0)) sun.diffuse = new BABYLON.Color3(0.8, 0.8, 0.8) sun.groundColor = new BABYLON.Color3(0.1, 0.1, 0.1) const box = BABYLON.MeshBuilder.CreateBox('active', { size: 0.9 }) const boxMaterial = new BABYLON.StandardMaterial('') boxMaterial.diffuseColor = new BABYLON.Color3(0.5, 0.5, 1) box.material = boxMaterial box.physicsImposter = new BABYLON.PhysicsImpostor(box, BABYLON.PhysicsImpostor.BoxImposter, { mass: 1, restitution: 0.9, friction: 1 }) }) </script> </head> <body> <canvas id='renderCanvas'></canvas> </body> </html> Any ideas why this code gives the following error? cannon.js:5756 Uncaught TypeError: Cannot read property 'calculateWorldAABB' of undefined at Body.computeAABB (cannon.js:5756) at Body.updateMassProperties (cannon.js:5930) at Body.addShape (cannon.js:5693) at t.generatePhysicsBody (babylon.js:43) at t.addImpostor (babylon.js:43) at t._init (babylon.js:43) at new t (babylon.js:43) at HTMLDocument.document.addEventListener ((index):32) I'm using the latest GitHub code `Babylon.js engine (v3.2.0-alphaC) launched`
  15. Hey guys, I'm trying to recreate the example code in Phaser 3 from this sample code as it seems Matter.js is much better suited for what I'm trying to achieve than Arcade and wanted to just get an example working locally.\physics\matterjs\attractors.js When I run this in my own project I get ` this.matter is undefined ` Is there a separate script I'm meant to include like there was in the dist folder for 'phaser-arcade-physics.js' on the repo
  16. I just tried to set the world bounds for a player sprite in a responsive game with the following config: const config = { width: window.innerWidth * window.devicePixelRatio, height: window.innerHeight * window.devicePixelRatio, parent: 'canvas', type: Phaser.AUTO, physics: { default: 'arcade', arcade: { gravity: {y: 2500}, debug: false } }, scene: [ Preloader, Game ] }; In the game itself, i created a player sprite like this: this.player = this.physics.add.sprite(this.screenWidth * 0.2, this.screenHeight * 0.5, 'coin'); this.player.setCollideWorldBounds(true); It places the object correctly, and on desktop the player object hits the ground and stops there. On mobile, it does not stop at the bottom though, because of the pixel ratio. Is that a bug? Or is there just some settings to use setCollideWorldBounds correctly on mobile devices and responsive games?
  17. Hello there, Is it possible to create destructible terrain in HTML5 and box2d Video examples : Box2d Destructable Box2d Destructable terrain Any help in this direction would be much appreciated. Thanks Again
  18. I have a sprite and a body that both rotate towards the pointer. On collision, though, the sprite sometimes gets turned away from the body. The body continues to point towards the mouse but the sprite does not (see image, definitely not the worst that it can be). I haven't found a way to fix this, anyone know how?
  19. Hello! I'm new to Phaser and HTML5 game development (but not to JS), and have been going through a few free tutorials online. I've already done the mobile toddler's game tutorial, and a simple sidescroller game tutorial, great fun so far! Today I tried to follow an infinite scolling game tutorial (not the same author and not as well written as the first two I followed), but I can't get it to work... The dog falls through the ground on collision with the fleas, and stays stuck down there while the game keeps scrolling. The dog also falls through the ground also after the digging animation... I compared my game.js code to the author's Game.js code, line by line, and didn't see anything missing – I even went so far as to reorder everything the same way she did (the other files were quasi-identical). This is what I found: If I only paste the author's code in place of mine: the game still doesn't work as expected. If I only use the phaser.js v2.1.3 file (from the downloadable source files), instead of the phaser.js v2.6.2 file I use: the game still doesn't work as expected. If I use both the author's Game.js file and phaser.js v2.1.3: the game works! I think that the article must be missing something that can be found in the author's code, because I followed the tutorial exactly. But given that swapping her code for mine still doesn't fix the game, does anyone have any idea what might be causing the player to fall through the ground on collision/overlap? Might it have something to do with gravity, or other physics in Phaser 2.1.3 vs 2.6.2? Thanks in advance!
  20. Hi, I'm syed and i'm new for phaser. how to add restitution for one object not for whole world Note: using P2JS physics engine
  21. Hi All, Disclaimer: I'm very new to Babylon. I was playing around with this cloth tutorial, and I wanted to make the cloth land on some sort of ground object. So far, I haven't been able to find one that works. You can see in this playground how the cloth reacts to a box impostor, side-by-side with a sphere behaving normally. I have the restitution of everything set to 0. The sphere stops nicely but the cloth shoots off into the distance. I've also tried this with a ground impostor (sphere works fine, cloth doesn't interact with the ground), and a plane impostor (cloth collides correctly, but sphere shoots up into the stratosphere). I have also tried adjusting the initial linear velocity of the cloth particles. More velocity = flies away faster, less velocity = falls right through the ground. My ultimate goal involves the cloth having an initial z velocity, so I'd like to be able to make that work. Can someone help me figure out what I'm missing here? Does it have something to do with the distance joints connecting the particles in the cloth? Should I try using sphere impostors instead of particles? Thanks! (side note: is there a better way to translate the cloth's position than the translatePositions function I made? The built-in ground.rotation.axis method rotates the cloth, but not the actual particles themselves)
  22. Hello again people! Well, I have a little problem with collisions in babylon with cannon js. For example: I move my player with translate, it's just a box with box impostor, and when I go and crash with another box the player is throw in the other sense, here it's all ok but the force with the player is throw it's very strong. I tried with resitution = 0 or friction = 1 but happens the same strong counter force. So, can anyone help me?
  23. I have used this phaser example as a starting point to build a game where shapes are dynamically dropped from the top of the screen and collide with each other: What I would like is for the shapes to stop bouncing and vibrating when they collide - but I'm not sure which settings to adjust to achieve this effect (and I've not had much luck with trial and error so far!). I have set gravity like this: game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.gravity.y = 6000; Here is my shapes/sprites json file: { "shapeOne": [ { "density": 2, "friction": 100, "bounce": 0, "filter": { "categoryBits": 1, "maskBits": 65535 }, "shape": [ 84, 76 , 0, 160 , 0, 0 , 84, 0 ] } , { "density": 2, "friction": 100, "bounce": 0, "filter": { "categoryBits": 1, "maskBits": 65535 }, "shape": [ 84, 76 , 314, 76 , 314, 160 , 0, 160 ] } ], "shapeTwo": [ { "density": 2, "friction": 100, "bounce": 0, "filter": { "categoryBits": 1, "maskBits": 65535 }, "shape": [ 0, 0 , 315, 0 , 315, 83 , 0, 83 ] } ], "shapeThree": [ { "density": 2, "friction": 100, "bounce": 0, "filter": { "categoryBits": 1, "maskBits": 65535 }, "shape": [ 0, 0 , 237, 0 , 237, 235 , 0, 235 ] } ] } Does anyone know the correct settings to adjust? Do I need to turn density up really high and friction low? And should gravity be high? Here is a screenshot of the shapes that are being dropped into the container:
  24. I am getting close to starting a social media promotion to "Release" my new game portal GuiGhost Games. My target is to go after the "Family Friendly" niche, and therefore sticks to games in that theme. All the games on my portal share the same bonus currency "StarCash" that can be earned and spent across the games. I have the Facebook integration currently turned off as the apps are still listed in Dev mode, so those items will not work, but thought I might get some outside opinions on the game play from this community first. Full Disclosure: These games are the product of me following tutorials that I extended, using open source examples that I skinned/tweaked to fit my style. The last year has been spent learning the ins and outs, following tutorials, as well as exploring the many frameworks available. All my games are targeted to be mobile friendly, and attempt to resize and look good on all devices. Some are just skins of open source code, and others started with a tutorial of the basic mechanics and grew into a full game play experience, such as GuiGhost Farms and Gui Bubble Story Here are a couple of screenshots from the games I spent the most time on. Shout out to, and for the great tutorials on getting started in HTML5 game development, and to all the great artists on for the open source assets used in these games. Some of these games are still a little rough around the edges, but I would appreciate any feedback before I start pushing this out on social channels.
  25. Hi Everyone, How to attach the two meshes using script. for example: Two meshes i) skateboard ii) player(animated with 3ds max) i will use this to attach sword.attachToBone(skeleton.bones[34], character); Note: i want to attach two meshes i) the skateboard don't move while playing the players animation Advance Thanks...