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 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 559 results

  1. Hi, Can I somehow (with physics plugin Oimo.js) set different gravity for different meshes? For example I want to simulate environment in water and I want to have there buoyancy. https://www.babylonjs-playground.com/#2B84TV#7 Thanks a lot for your advice.
  2. Collisions with sprites

    I am making a game where I need to know if a sphere has collided with an enemy. The problem I have is that the enemies are sprites. Is there a way to check collisions with sprites?
  3. I have a mian body that moves freely on the board. To that body I want to attach a recrangle at a certain offset that would visibly dangle and rotate upon forces affecting the main body. How could I achieve that? I tried a set of springs, but I can't get the desired effect.
  4. Hi, i want capsule imposter for my caracter but how can i done that. i'm using cannon.js plugin any other physics engine can support it
  5. So a gotcha of the moveWithCollisions method is that it uses an ellipsoid mesh to calculate collisions of your mesh instead of the original mesh dimensions. I see a clear way to remove your original mesh but how do we remove the ellipsoid mesh from the scene? I'm worried that keeping these ellipsoids even when my original mesh has been disposed of will hurt performance. Thank you so much.
  6. I saw this on Facebook, from a mate of mine: https://fitting3d.com Pixel perfect cloth physics and collision in realtime. Also works on mobile devices. Can Babylon.js do this? Edit: Just realised, maybe the physics was baked into vertex animation instead, 'cos it doesn't look like you can interact with that animation
  7. Clamp Player movement

    hi, i need a help. i want to clamp the player movement in certain range. how can i fix it. now i'm using following method the moveleft & moveright is a boolean function. it is working fine. but if the character repul while colliding with collider. then the character move across the given limit. how to clamp it. if (player.moveRight && player.position.x <= 42) { player.position.x += 1; }; if (player.moveLeft && player.position.x >= -42) { player.position.x -= 1; };
  8. hoverboard setup

    Hi, i'm newbie. i need a help to setup hoverboard. The player should have physics engine and the same time the player always maintain a some gap between the board and track.
  9. Body vs Sprite (ARCADE physics)

    Hello to everyone, I am new to Phaser. These days I am studying the tutorials and I suddenly came across the many problems related to sprite of different dimensions. So I am learning to use Texture Atlas. I have create an animation with the related json file. All work just fine (visually). Playing with the json file I am able to adjust the sprite width (green box) but not the body size (red box). The ARCADE Physics has only ONE box size? Is there a way to automatically adjust the body size following the sprite size? Or I must move on onto more complicated physics. Thanks to enyone who can help me.
  10. Physics with touch to move player

    I am making a maze game where the player drags their finger to control a ball moving through a maze. I would love to use Phaser physics to block the ball from moving through the walls. Is there a way to do this with Phaser physics and if so, which physics type would be the best suited for this?
  11. Hey! I think this is going to be another one of those, "oh right, it's this" sort of questions, but after tinkering with it for far too long, I figured I'd tap into the brain trust that is this forum. I have a cylinder nested inside Epcot Center an icosphere. Both of these will have a mass of zero. Here's the PG: https://www.babylonjs-playground.com/#UGTGRU. Move your mouse over the icosphere—the cylinder positions/rotates along the picked facet/normal. Click the icosphere to enable physics and set the impostors starting with the cylinder, then the icosphere. Notice that the icosphere's rotation jumps Here's what I'm wondering: Since these things aren't supposed to move in my scene (since the mass === 0), how could I go about setting up these physics impostors in such a way that would preserve the rotation/position of the icosphere and the cylinder at the moment it's clicked? Also, what if the impostor hierarchy is three+ levels deep? Also wondering: Could the icosphere and cylinder (parent/child) impostors have different restitution and friction values? Thanks!!
  12. Physics bug

    Box2D always calls contact callback twice. Here's an example: 185.50.68.103 Ship with collision category 2 (ship at left) calls contact callback once while ship with collision category 1 (default) calls it twice. I've been trying to fix this for weeks but couldn't find any solution in web, i really need you guys to help me. function create() { game.physics.startSystem(Phaser.Physics.BOX2D); game.stage.backgroundColor = '#2d2d2d'; // User-controlled ship ship1 = game.add.sprite(250, 300, 'ship'); game.physics.box2d.enable(ship1); ship1.body.setCircle(14); // Ship with collision category 2 (triggers contact callback only once, it shouldn't even trigger it) ship2 = game.add.sprite(200, 200, 'ship'); game.physics.box2d.enable(ship2); ship2.body.setCircle(14); ship2.body.setCollisionCategory(2); // Ship with collision category 1 *default, i guess* (triggers contact callback TWICE) ship3 = game.add.sprite(300, 200, 'ship'); game.physics.box2d.enable(ship3); ship3.body.setCircle(14); game.physics.box2d.setBoundsToWorld(true, true, true, true, false); ship1.body.setCategoryContactCallback(1, function(b1,b2,f1,f2,begin){ if (begin){ total += 1; hitText.text = 'Contact callback called '+total+' times'; console.log("CONTACT: ", b2) } }, this); cursors = game.input.keyboard.createCursorKeys(); game.add.text(5, 5, 'Use arrow keys to move.', { fill: '#ffffff', font: '14pt Arial' }); total = 0; hitText = game.add.text(5, 30, 'Contact callback called 0 times', { fill: '#ffffff', font: '14pt Arial' }); } function update() { if (cursors.left.isDown) { ship1.body.rotateLeft(300); } else if (cursors.right.isDown) { ship1.body.rotateRight(300); } else { ship1.body.setZeroRotation(); } if (cursors.up.isDown) { ship1.body.thrust(300); } else if (cursors.down.isDown) { ship1.body.reverse(300); } } function render() { game.debug.box2dWorld(); }
  13. Let's say you have a sprite with a collision body of 16px/16px and all the areas to move in the map are exactly 16px/16px as well. It's very hard to maneuver the sprite to be at exactly in the opening to avoid collision letting the player move through it. For example, I attached a gif I made of how Bomberman solves this problem: Bomberman allows the player to clip slightly into the corner of the tile when they get close to the edge so the player starts moving diagonally into the open gap so then the player doesn't have to worry about lining up perfectly. I've looked into doing that but collision detection is AABB on tiles. I also can't just set the players x/y coordinates to be in the right spot because that will break any other collision physics going on. So is there a way to round the corners like in Bomberman or to use velocity to position the player in the opening of the lane perfectly or any other ideas I'm not thinking of? Thanks
  14. When adding a rectangle to a p2 body you have the option to specify a rotation in radians for the shape which it appears is just passed directly on to the p2 shape constructor (hence the need for it to be in radians instead of degrees as are used elsewhere in Phaser). I find that if I use any value other than 0 for a rotation, the shape is properly rotated however drawing of the body via the debug parameter ignores the rotation. Here is a quick codepen illustrating the bug. The character should have a long protrusion coming out the bottom achieved with a rotated rectangle. The physics collision seems to indicate that the rotation has occurred correctly, however the debug shape is not drawn rotated. Notice that he appears to sit a little ways off the ground due to the un-rotated debug visualization of the shape. It seems to me this must be a bug (or maybe a limitation of the debugbody drawing system) but I thought I would post here first for thoughts. I will likely dig in and see if I can find a fix / workaround for this. Phaser P2 DebugBody rotation bug (codepen)
  15. Hey! I'm using NullEngine on a server to check for certain conditions in a physics-enabled scene (using deterministic lockstep). As a simple example, I'm trying to find the specific step ID where a specific ball's y position falls below 0. My question is this: how should I set up the engine/scene/etc. in order to run these server-side simulations at the highest possible fps? Keep in mind that I want to be able to derive a list of step IDs on the server that correspond with specific events (re: ball.position.y < 0), and then have that same exact scene play in a browser with the same exact events matching the same exact step IDs.
  16. Hi everyone, I just wanted to share a new Phaser Plugin called phaser-tilemap-plus, that extends the tilemap loader and factory to support tile animations defined in the Tiled editor. It also allows you to implement collision detection against the map using polygons and rectangles within an object layer, enabling the use of sloped and curved surfaces. It will eventually also support custom properties and region-based events via the object layer. You can access and build the library from GitHub or install it directly as a Node package via NPM. Please note that it is still a work in progress, with features that are yet to be added and kinks to iron out. Anyhow, let me know what you think!
  17. Hi guys! Jus wanted to update regarding a new feature that was pushed today. Until today any mesh with a parent couldn't have its own physics impostor and was considered to be a part of a compound along with the parent. This behavior can now be controlled using a new flag in the impostor options (part of the constructor. The behavior can be best seen in this simple playground: https://playground.babylonjs.com/#PRHF00 . The right sphere is a simple mesh and has no impostor. the left sphere has its parent set to the right sphere, and the impostor is set with the ignoreParent flag. The right sphere's position is still updated when the parent mesh is moving, but it is also being controlled by the physics engine. Fun times!! Another flag that I added has the amazing long name disableBidirectionalTransformation (a boolean). This flag will disable the bidirection transofmration between the physics engine and babylon, meaning - changing the mesh's position in babylon will practically do nothing. The object will be controlled solely by the impostor. This is done to add a performance boost, as the transformation step is being skipped. I am here for any questions! The playground is not fully updated, so this feature will be there pretty soon. Until then you can think what you can do with it
  18. Version 2.9.1 (phaser-ce) I'm seeing some unexpected behavior with the physics body of child sprites lagging behind when accelerating the parent. So when debugging the bodies, they appear slightly offset in the opposite direction of the movement: This is the code for an example I made to illustrate my problem: var game = new Phaser.Game({ state: { preload: function() { this.load.baseURL = 'https://examples.phaser.io/assets/'; this.load.crossOrigin = 'anonymous'; this.load.atlas('spritesheet', 'atlas/megasetHD-1.png', 'atlas/megasetHD-1.json'); }, create: function() { this.physics.startSystem(Phaser.Physics.ARCADE); this.createVegetables(); }, update: function() { this.vegContainer.body.acceleration.y = 50 * this.time.physicsElapsedMS; }, render: function() { this.game.debug.physicsGroup(this.melons); this.game.debug.physicsGroup(this.mushrooms); }, createVegetables: function() { // Create veg groups. this.melons = this.add.group(); this.mushrooms = this.add.group(); // Container. this.vegContainer = this.add.graphics(); this.vegContainer.addChild(this.melons); this.vegContainer.addChild(this.mushrooms); const height = 120; const x = 350; for (let y = 0; y > -1000; y--) { let sprite; let isMelon = Math.random() > .5; if (isMelon) { sprite = this.melons.create(x, height * y, 'spritesheet', 'melon'); } else { sprite = this.mushrooms.create(x, height * y, 'spritesheet', 'mushroom'); } sprite.scale.set(3); } // Enable physics on container and all children. this.physics.arcade.enable(this.vegContainer); this.vegContainer.body.maxVelocity.y = 800; } } }); and this is the code pen link. It will work as expected if I accelerate the groups individually but this is not ideal as there are quite a lot of groups in the game. Is this a bug or is it working as expected?
  19. Phaser P2 Physics - Apply Force

    I am attempting to apply force manually to a sprite that has a P2 physics body. My hope is to achieve the designable jump described by Kyle Pitmann in his GDC Talk below. In this he derives equations for a jump arc that are controlled by the height, footspeed, and how long the jump should last. It will give you a gravitational force and an initial velocity to achieve those parameters. Everything I do to try and set a manual force on the P2 body is being ignored. Here is what I have: Gravity on the body is disabled via body.data.gravityScale = 0 I then try and initiate a jump using my precomputed initial velocity and gravitational constant as follows: let vx = config.WALK_SPEED sprite.body.force.y = this._jump_grav_start * vx * vx sprite.body.velocity.y = this._jump_vel_start * vx Afterwards I dump 'force' to the console and it is always zero no matter what I try to set it to. Am I just missing something fundamental here about how you apply a force in P2? Seth B. )
  20. I'm trying to create simple physics impostors for relatively complex models (to create CPU-friendly yet fairly accurate hitboxes). I noticed the scene.createCompoundImpostor method would likely work nicely for this sort of thing, but it was dropped in v3.0. What is the recommended strategy for v3.0? As an example, I'd like to create a hitbox for something like this: ...using an array of primitives, like this: edit: here's another example...
  21. Hey guys, I was profiling my game and it seems like I could save some cpu time if I could bypass this function call in my objects' postUpdate : postUpdate: function() { ... if (this.components.PhysicsBody) { Phaser.Component.PhysicsBody.postUpdate.call(this); } ... } My question is, since my game doesn't use any physics at all, do I have to rebuild phaser without physic support? Or is there a simpler way to simply disable the creation of physics body on all my game objects? Thanks for any input!
  22. I'm a newbie to the 3d dev world... WOW, the learning curve is HUGE! At any rate, I thought I would give Babylon.js a shot... I watched the learning series on Microsoft Virtual Academy with the two David's... In the materials example they show an example of creating 10 spheres in a circle surrounding a single sphere... That was the start of a simple idea I wanted to implement on a home page... I would like to create a wheel of objects that a user could spin... and a random object would stop center screen showing the result of the spin... I want a vertical spinning series of objects... Not like a money wheel or vertical roulette wheel, but more like a slot machine wheel, or think "the price is right wheel", where players spin the wheel to get closest to $1... My layout is very basic, and I simply need some assistance with how to go about animating something with physics... i.e. make the wheel look random and look realistic. Most of the examples I find show creation of scenes and objects, and perhaps some basic animation, but to create a game seems like it would be a huge undertaking. Assets (meshes) not withstanding, game logic seems like... well... formidable! I would also like some assistance with game code organization... Is there documentation on a logical order to store scripts and assets? * things I've determined from trial an error... The number of points should be evenly divisible by 360 in order for an object to be centered center screen... In this example the number of objects is 24, and the radius is 3... This centers an object center screen... If I use 16, and a radius of two this will also work for my needs... Now I would like to animate the spinning of this "wheel of objects", and have some sort of physics working to make the experience realistic... var createScene = function () { var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3(0, 0, 0); var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 0, -6), scene); camera.setTarget(BABYLON.Vector3.Zero()); camera.attachControl(canvas, false); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 0, 0), scene); var points = 24; var radius = 3; var slice = (2 * Math.PI) / points; for (var i = 0; i < points; i++) { angle = slice * i; var obj = BABYLON.Mesh.CreateBox("box" + i, .65, scene); obj.position.y = (0 + radius * Math.cos(angle)); obj.position.x = -1; obj.position.z = (0 + radius * Math.sin(angle)); } return scene }
  23. Handle diagonal car ramp

    Greetings from a newbie in Phaser. In a 2d car game, how do you imagine a car ramp? Is there any way to draw a diagonal object and when the car object hits that start decreasing the angle and increasing the position.y? Progress! I started with Phaser.Physics.P2JS ( had to quit using Phaser.Physics.ARCADE ) Then make an sprite and assigned a Polygon: preload(){ this.load.physics('physicsData', '/app/dist/sprites.json'); } create(){ game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.gravity.y = 50; game.physics.p2.defaultRestitution = 0.01; ramp = game.add.sprite(100, 100, 200, 100, "block"); game.physics.p2.enable(ramp); ramp.body.clearShapes(); ramp.body.loadPolygon('physicsData', 'ramp'); } My sprites.json is: { "ramp": [ { "density": 2, "friction": 0, "bounce": 0, "filter": { "categoryBits": 1, "maskBits": 65535 }, "shape": [ 200, 0 , 200, 100 , 0, 100 ] } ] } I think I got it. Any advice is good
  24. So, which one to choose? Which one is more performant? Which one has most features? Which one is better documented?
  25. Hello! I am new to these forums and I just have to say Babylon.js is now one of my favorite libraries for webGL. I have finally switched over from three.js and have to say this has been so much fun to play with. Just recently I am trying to make a physics-based environment where you can pick up and drop objects similar to the old source engine and garry's mod. I created this playground to show an example of what I am trying to create but some of the bugs are shown in the gyazo link. https://playground.babylonjs.com/#0H29AJ https://i.gyazo.com/bc01aaaced057c158f1c925cfafc06a2.mp4 The object, when held and looking downfalls through the floor. Sometimes when dropped it becomes at a sliding state where it will not stop sliding and on pickup, it will fall through the floor. So my question is, how can I stop the object from going through the floor?