Search the Community

Showing results for tags 'physics'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 476 results

  1. I made a pretty good Frogger clone using PhaserJS, but when refactoring the code, I ran into a very, very strange problem. My vehicles currently have a velocity of 200. When Frogger collides with one of them, that vehicle's velocity drops in half. Frogger also gains the velocity of that object. In update this.game.physics.arcade.collide(frogger, vehicles, this.loseLife); Here's my vehicles code objects.forEach(o => this.game.physics.arcade.enable(o)); [normalCar1, normalCar2, normalCar3, specialVehicle1, specialVehicle2, specialVehicle3, emergencyVehicle1, emergencyVehicle2, emergencyVehicle3].forEach(function(object) { object.body.velocity.x = object.direction == 'right' ? 200 : -200; }); Here is my loseLife() function loseLife: function() { /*switch (frogger.health) { case 5: lifeFive.destroy(); break; case 4: lifeFour.destroy(); break; case 3: lifeThree.destroy(); break; case 2: lifeTwo.destroy(); break; case 1: lifeOne.destroy(); break; }*/ frogger.damage(1); gameState.resetPosition(); gameState.resetRows(); /*if (!frogger.alive) { clearInterval(sinkLillies); game.state.start('gameover'); }*/ }, The important method here is resetPosition() which moves Frogger back to the starting position resetPosition: function() { frogger.alpha = 0; frogger.x = this.game.world.centerX; frogger.y = this.game.world.height - 18; game.time.events.add(1000, function() { this.game.timer = 50000; frogger.alpha = 1; }, this); }, The important thing here is that I do not specify that I want the velocity to increase Hopefully, a video will make it easier to understand https://webmshare.com/DmoAQ Edit: A temporary working solution I was able to "solve" this by adding this line in the resetPosition() function frogger.body.velocity.x = 0; And to remove that weird behavior of the car slowing down objects.forEach(function(object) { this.game.physics.arcade.enable(object); object.body.immovable = true; }); This is a hack though. I shouldn't have to explicitly add these lines, because collisions shouldn't cause this behavior in the first place.
  2. Hi @all, Is there a problem with the HeightmapImpostor? In my test application dont work the pyhsics anymore. The player and other objects fall now through the ground. let groundFHM = BABYLON.Mesh.CreateGroundFromHeightMap("groundFHM", "textures/heightMap.png", 100, 100, 100, 0, 10, scene, false, function () { ... groundFHM.physicsImpostor = new BABYLON.PhysicsImpostor(groundFHM, BABYLON.PhysicsImpostor.HeightmapImpostor, { mass: 0, friction: 0.2,restitution: 0.3 }, scene); }); In this Demo from @Wingnut http://www.babylonjs-playground.com/#1RKZXB#6 works the physics also not correct at all. Edit: In my older babylon.js alpha version this works by the way
  3. How to use P2 Physics with each layer object? Code this.saws = this.game.add.group(); this.saws.enableBody = true; this.map.createFromObjects('saws', 4, 'saw', 0, true, false, this.saws); this.saws.forEach(function(saw) { saw.body.clearShapes(); saw.body.loadPolygon('physicsData', 'saw'); });
  4. hi guys I found out low frame rate slow down physics update too. (in arcade & p2 physics) for instance, in same gravity settings, results are different depending on frame rate. (body hits the ground more faster in the higher frame rate environment) I don't know much about game engine or framework, but I think it is more appropriate that physics updates by elapsed time, not by frame count. I came to think Phaser is really well made framework after looking into examples on official websites, and I don't think Phaser creator didn't think about this issue. I googled about this issue, but couldn't find any answers that suit on me. (probably because of my poor english) I would be appreciated if you give me any clue.
  5. Hello, I'm working on a realtime multiplayer game and I'm running into a problem with the physics that I'm unsure how to correct. Basically when one player jumps on top of the other from a high distance, it pushes the other player through the platform and the player gets stuck there. Here is the code for the platforms: PlayState._spawnPlatform = function (platform) { let sprite = this.platforms.create( platform.x, platform.y, platform.image); // physics for platform sprites this.game.physics.enable(sprite); sprite.body.allowGravity = false; sprite.body.immovable = true; this.game.debug.body(sprite); }; And here is the code for the players: PlayState._spawnCharacters = function (data) { this.hero = new Hero(this.game, 10, 10); this.hero.body.bounce.setTo(0, 0); window.globalMyHero = this.hero; window.globalOtherHeros = this.otherHeros = new Map(); this.game.add.existing(this.hero); sendKeyMessage({}); }; And here is the collide function between the platform and all of the global players: this.game.physics.arcade.collide(otherplayer, this.platforms, null, null, this); Does anyone have any recommendations on how I can make the players not get stuck in other physics objects? Thank you for the help.
  6. Our new tool, Loon Physics, has just been released to open beta for free! Try it now to export P2 Physics body polygons for Phaser. Use a URL to test live without exporting files. Use Loon Physics here: https://loonride.com/physics Learn how to make a game with P2 Physics using this brand new tutorial: https://loonride.com/learn/phaser/p2-physics-bodies
  7. phaser

    I have a quick question that I need to ask. I am using Phaser 2.6.2 and was wondering if I could get some help on detecting nearby overlaps using P2 exclusively (at the moment and I would hope to keep it that way for the purpose to not manage multiple physics engines). So my question is, how do I go about this? I am new to Phaser and had troubles finding working examples. OR If anybody has good solutions to the problem of real time combat in a top down 2D game with melee weapons and how to detect hits efficiently, that would be great! I also need this type of proximity detection for my AI as well, so that would be awesome too! THANKS!
  8. I'm working on a Pachinko-like game and have a question about physics. I'm new to Phaser, so if this is an obvious answer, sorry! I have a star-shaped pin wheel thing. I need it to be stationary but rotate around its anchor point when hit by an object (based on physics). How would I go about making it stationary, but allowing it to be rotated based on objects colliding with it? (I know how to get the polygon collision using the Physics Editor, I'm just not sure about the rotation part). Any help will be greatly appreciated! Thanks.
  9. Howdy! I was so tired of searching free 2D physics body editor to Phaser.io, so I decided to create one myself. It works and it is quite accurate. Making physics bodies doesn't take that much time. The project is in early update, I was wondering if you would like to see more. I give you it in a file to download and here is my question - where should I host/share the project so everyone can see it after 1 click and can it be free (I am a poor kid)? I am always willing to answer wo997 physics.zip
  10. We recently released a tool for editing P2 Phyics body polygons called Loon Physics. Check it out here: https://loonride.com/physics Read a tutorial about P2 Physics bodies and Loon Physics here: https://loonride.com/learn/phaser/p2-physics-bodies Do you find Loon Physics useful? Do you encounter any bugs when using the tool? Any suggestions?
  11. Hello, I am building an Oceanic game and need to utilize the water surface. I am swimming fish through the sea however at angle '0' I want to fish to be pointing up and not left. I do this by creating the angle 90 degrees: this.xSpeed = Math.cos((this.fishBody.angle+90)/180*Math.PI) * -this.pSpeed; this.ySpeed = Math.sin((this.fishBody.angle+90)/180*Math.PI) * - this.pSpeed; However, I run into problems down the road with AI Fish.prototype.avoid = function(fishBodx, FishBodY, xsp,ysp){ var targetAngle = this.game.math.angleBetween( xsp, ysp, fishBodx, FishBodY ); if (this.fishBody.rotation !== targetAngle) { var delta = (targetAngle) - (this.fishBody.rotation); this.TURN_RATE = 3; // Keep it in range from -180 to 180 to make the most efficient turns. if (delta > Math.PI) delta -= Math.PI * 2; if (delta < -Math.PI) delta += Math.PI * 2; if (delta > 0) { // Turn clockwise this.fishBody.angle += this.TURN_RATE; } else { // Turn counter-clockwise this.fishBody.angle -= this.TURN_RATE; } // Just set angle to target angle if they are close if (Math.abs(delta) < this.game.math.degToRad(this.TURN_RATE)) { this.fishBody.rotation = targetAngle; } } } What is a good solution to this?
  12. hi, i'm coding a pinball game in js with phaser and p2physics. I search how i can do rotation with a anchor point. I want create the rotation for the flipper but method rotateLeft or rotateRight do the rotation by the center's sprites. I want create a rotation around topleft and top right point of the sprite to do a flipper movement. orry for my bad english, thx.
  13. Hello, As some of you may know, we have been forced to introduce a breaking change in the way to use the physics engines starting with v2.4. We try as much as possible to avoid breaking but sometimes it can help introducing a much better way to achieve something. This is the case for physics as now, the physics impostor and its associated mesh are better linked. To better understand why, extract from the doc: "The physics impostor synchronizes the physics engine's body and the connected object with each frame. That means that changing the object's position or rotation in Babylon code will also move the impostor. The impostor is also the one updating the object's position after the physics engine is finished calculating the next step". In previous implementation, we had a lot of users questions & feedback that didn't understand why moving the mesh wasn't doing anything once it was transformed into a "physic object". Please read our documentation to better understand how to use physics in Babylon.js: http://doc.babylonjs.com/overviews/using_the_physics_engine I've then updated my tutorial and the default sample of our main page: - Understanding collisions & physics by building a cool WebGL Babylon.js demo with Oimo.js: https://www.davrous.com/2014/11/18/understanding-collisions-physics-by-building-a-cool-webgl-babylon-js-demo-with-oimo-js/ - Main sample: http://www.babylonjs.com/Demos/Physics/ Thanks! David
  14. Play at: Space Captain vs Mega Robots
  15. hy room, i've been trying to control the bounce of the ball in this pg after it falls of from the plane, it goes back to its original position but gravity is pulling it up here'sthe pg: http://www.babylonjs-playground.com/#BEFOO#145 click on the plane to make the ball fall
  16. This is version 2 of my game Descensus from several years ago. It's a simple but difficult 2D physics game in which you have to guide the ball to the ground by swiping bars on screen, bouncing it around spinning saws and off moving terrain objects. There's a time limit to reach each 100m stage, and you can use terrain objects to your advantage as well. It was written using the physics library p2.js and the rendering library Pixi.js. I wrote in in TypeScript, bundled with Webpack, developed using Visual Studio Code. The Android version was packaged using the cloud build system Monaca, bundling the Crosswalk webview (hence the relatively large APK size). It doesn't use any PhoneGap APIs - the sound is all HTML5 Audio. I did most of the testing on desktop so I know that it works nicely with both mouse and touch. I might possibly put it online in the future. Play Store link: https://play.google.com/store/apps/details?id=com.booleanoperations.descensus2 Video: https://www.youtube.com/watch?v=9BWii8aokbQ
  17. Hi just started to use babylon js Would like to have some sugestions on physics animaton. I have cylinder like mesh and inside in it is small sphere. I need to animate ball so that it push to border of cylinder and moves along it in cw direction, like centrifuge. Can i do it using physics? Till now i did it using posotion changes but as i need to slow down it would be nicer with some forces. One way I thought of is to calculate angle from center and apply impulse away from center and slighty forward but maybe there is better way.
  18. Hi, I imported a mesh and then separated it into two objects. Basically a wheel and a stand for the wheel. And I want the axle for the wheel to fall onto the stand and allow me to spin the wheel. My problem is that I can't get the physics to work right. I either drop things through the floor or gravity doesn't work at all, depending on the different engines and things I've tried. I'm new to babylonjs so perhaps I'm doing wrong something that's simple to see. My code is at http://www.babylonjs-playground.com/#2I8LFS#2 If anyone can see what I'm doing wrong, I'd much appreciate it!
  19. First of all, sorry for my english Hello! I'm trying to make a Arkanoid game on android Phaser. When the ball hits a brick, the brick disappears and the ball bounces well. Now I have two types of bricks, a normal brick, brick and TNT brick. I've implemented that when the ball touches a TNT brick, kill adjacent bricks too, but when one of those adjacent bricks is a TNT brick, it must call the same function recursively, but something does not work ... any idea? here is my function:
  20. I have recently run into a problem with the physics joints in Babylon. I add a distance joint between two impostors in my scene, but after some time, I would like to remove that joint. Currently on the docs, there is no reference to a removeJoint function, and after looking into some of Babylon's source code, I found the function link: https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/babylon.physicsEngine.ts However, the function appears as if it is not complete, and I am unsure of the proper way to access it. Is there a way to properly remove a physics joint?
  21. Hi, have a problem with parenting physics objects together. Here an easy playground: http://www.babylonjs-playground.com/#AF886#1 Why is b dont collide with the ground too like the parent? I want both collide the ground and behave like one. Is it a bug?
  22. Hi @all, I think I found a bug again. In this PG: http://babylonjs-playground.azurewebsites.net/#249T6Y Edit: New URL:http://www.babylonjs-playground.com/#249T6Y I change friction for a to zero but friction b becomes zero too (See console too) If it is no bug, please tell me how can I change the friction for just a.
  23. I have always used "setPhysicState" to set physics properties of objects, in many projects. Meanwhile I read it's better to use "new BABYLON.PhysicsImpostor" instead. Why should that be better? What are advantage and disadvantage?
  24. Hi! I am new to Babylon.js. Love it so far. I am trying to write a simple game. I want the game character to "float" over the playing field. Right now, I'm just trying to get a simple box to hover. I'm doing it in a somewhat funny way because I want some wobbling to occur as part of the hover. I am trying to use physics. So I have gravity enabled in the scene and collisions enabled for the meshes. Further, I want to apply impulses to the box to get it to hover. I wrote some code to figure out which vertex is the "lowest" of all the verticies of the box. I then apply an impulse to that vertex. Because the vertex is extended from the centroid of the box, a torque is generated by the impulse. I am having difficulty keeping the impulses in range. Typically, without squelching the angular velocity, the box eventually starts rotating out of control. So, I was looking into just manually leveling the rotation using addRotation. First I get the Euler angles from the rotation quaternion. Then I reverse a little bit back onto the box each frame. Oddly, this seems to work very well for about 1 minute. Then suddenly, it fails. I fails slowly, which is even odder to me. It seems like I have to reset some internal state or something.... Can someone point out my missteps? Thanks. Wingnut was kind enough to build a playground example that works (but without the wobble): http://babylonjs-playground.azurewebsites.net/#1GWEVG#0 (see his post below). I also have a running version on my website, at: http://165.225.132.154/graphics/BabylonHover/ When I fix the issue, that site will be updated. This snippet shows the original issue. Notice the difference between the working demo Wingnut wrote and this one which doesn't (specifically: the impulses are applied at the verticies here, whereas in the working example, the impulses are applied to the centroid): let dHoverHorizon = 50; let dImpulseForceDivisor = 10; let dRotationAdjustmentFactor = 20; meshBox.registerBeforeRender(() => { try { // Get all the verticies of the mesh, given as an array of 72 floats. // 3 floats for each vertex * // 4 verticies per face * // 6 faces. // // Question #1: Why all 6 faces, which produces 3 times as many verticies as necessary? // Question #2: Is there a way to combine these to remove redundant geometry? let arrayMeshVertexFloats = meshBox.getVertexBuffer(BABYLON.VertexBuffer.PositionKind)._buffer._data; // Extract the 4 verticies for the // face in which we are interested. // This happens to be the 6th face. let arrayMeshVerticies = []; for (let i = 3 * 4 * 5; i < arrayMeshVertexFloats.length; i += 3) { arrayMeshVerticies.push(BABYLON.Vector3.FromArray(arrayMeshVertexFloats, i)); } // Convert these 4 verticies to world coordinates. let arrayWorldVerticies = arrayMeshVerticies.map((vertex) => { let vertexWorld = BABYLON.Vector3.TransformCoordinates(vertex, meshBox.getWorldMatrix()); // Attach original mesh-vertext to the world-vertex. vertexWorld.localVertex = vertex; // Return the new vertex. return vertexWorld; }); // Just for fun, only allow impulse on the lowest of all verticies. let v3Lowest = null; arrayWorldVerticies.forEach((v3) => { if (!v3Lowest || v3Lowest.y > v3.y) { v3Lowest = v3; } }); // Drop out now, if lowest vertex is above hover-horizon. if (v3Lowest.y > dHoverHorizon) { return; } // Generate an impulse proportional to a square- // root of the drop down from the hover-horizon. let dImpulseForce = Math.sqrt(dHoverHorizon - v3Lowest.y) / dImpulseForceDivisor; // Get the linear velocity. let v3LinearVelocity = meshBox.physicsImpostor.getLinearVelocity(); // Only care about the y-axis. let dLinearVelocityAlongYAxis = v3LinearVelocity.y; // If the velocity is negative, then increase the impulse. // Eventually, this will need to take mass into consideration.... if (dLinearVelocityAlongYAxis < 0) { dImpulseForce *= (1 - dLinearVelocityAlongYAxis); } // This doesn't seem to work in a madening way: // Actually, it works for about 1 minute, then // just slowly and seemingly-deliberately fails. let v3Rotation = meshBox.rotationQuaternion.toEulerAngles("XYZ"); meshBox.addRotation(-v3Rotation.x / dRotationAdjustmentFactor, -v3Rotation.y / dRotationAdjustmentFactor, -v3Rotation.z / dRotationAdjustmentFactor); // Apply an "up" impulse to the physics // imposter at the local location of the // lowest vertex found during this pass. meshBox.physicsImpostor.applyImpulse(new BABYLON.Vector3(0, dImpulseForce, 0), v3Lowest.localVertex); } catch (e) { console.log("Error in meshBox.registerBeforeRender: " + e.message); } });
  25. Is the there some kind of PUBLISHED list of breaking changes that is going to happen when i using the Preview release versions... If i make changes to the github.. i have to use that version (i.e. i made a bunch of little changes to the 2.6 version). Now i can't seem to even find 2.6 and current preview version now using 3.0 ... But apparently there are BREAKING changes in the api from the 2.6 we been using the past few months to this new 3.0... Some kind of generics for Gamepads and now setPhysicsState is NO LONGER on the AbstractMesh... SO FAR ... that all i found. So My question is ... Is there some kind of LIST or ANNOUNCEMENT that is says 'Hey we made breaking changes and this is how you use the new stuff' ??? So how i am to use Physics With this new version (That also has my changes from the missing 2.6 version that was working fine). And the Gamepads ???