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
    • Facebook Instant Games
    • Web Gaming Platform
    • 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 665 results

  1. So hello, I am working on a maze game project. There are two players and both of the players send 2 velocity data as i try to simulate the players like a line follower robot(left motor and right motor). I use Cannonjs to create a heightmap impostor as the maze and 2 sphere impostors as the players. I move the players inside the maze as one of them tries to catch the other. Data is communicated with websocket. When players send 2 velocity data(left motor and right motor) i send them back their positions and an array of 180 distances like a view so they can locate eachother in the maze and decide where to go. So i move each of them like this: left_motor, right_motor as the velocities one of the players, i calculate angle with motors and use the angle for x_vel and z_vel, linear_vel = (left_motor + right_motor)/2 player.physicsImpostor.setLinearVelocity(new BABYLON.Vector3(x,0,z)) setTimeout(function(){ player.physicsImpostor.setLinearVelocity(new BABYLON.Vector3(0,0,0)) }, 10) and when sending message back to players i put a setTimeout(sendmessage(player1, player2), 50) so when i create a test game and set players' velocities to 10 for both motors and print players' positions everytime players send new values, i realised that the difference between positions of both players change by 10 and sometimes 20. This happens for both players and it does not happen at the same time to both of them. I use a password system so i am sure a player's data does not get sent over to other player. I tried to increase the timeout on send message to 1000 and that made no difference. I checked that linear_vel is always 10 so it never gets doubled. I am curious about the reason why it is sometimes 20 sometimes 10? Is it some weird interaction between setTimeout and setLinearVelocity?
  2. Hi everyone, I'm pretty new to Phaser, only started with it yesterday. I'm building a world with some image assets, in this case, trees that my player object will have to collide with. The code looks like this: var treeLeft = this.matter.add.image(0, (gameHeight - 96), 'tree', null, { isStatic: true }).setOrigin(0, 1); As you can see I'm adding them with Matter.js and then telling them to be static. However, my setOrigin(0, 1) is throwing off the bounding box that Matter.js assigns to the image object. Do you know of any way to make the physics bounding box coincide with my image's visible bounds? I'd like to keep the setOrigin as is because it simplifies the actual map building process for me greatly. Thanks in advance, Emile.
  3. Howdy friends! I'm proud to share my first production WebGL project: https://cash.me/reps (Scroll down to enter the game mode) Uses: GLTF assets Metallic Roughness Physics Camera Movements Force Touch on compatible devices Screenshots: Huge thanks to the community for helping answer my questions as I got up to speed! Especially @Deltakosh @bghgary @donmccurdy and @Wingnut
  4. Hi Everyone, i'm using physics editor software for apply p2 physic in phaser. i will apply the JSON in phaser game.load.physics('Physics', 'assets/sprites/newSize.json'); but i will get this layour in my png how to hide the marked area of the JSON
  5. 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: http://playground.babylonjs.com/#UGLFTI#1
  6. Her is an example based on a Phaser 2 example, 0 index is set as colliding: Her is the tiled json file: https://examples.phaser.io/assets/games/starstruck/level1.json Phaser 2 example where empty (index 0 in tiled json) is not collideable: https://phaser.io/examples/v2/games/starstruck What is the easiest way to fix this in phaser 3? Setting 0 in setCollisionByExclusion method does not exclude it from collision.
  7. 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); }
  8. 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?
  9. 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 = this.physics.add.group(); ... columna.setVelocityX(-200); Thanks!
  10. 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.physics.world.collide(this.plat, 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.physics.world.enable(this); 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); this.scene.events.on('update', this.update, this); } update() { if(this.data.active) { console.log(this.body.blocked.down) if (this.controls.left.isDown) { this.setVelocityX(-200); this.anims.play('left', true); } else if (this.controls.right.isDown) { this.setVelocityX(200); this.anims.play('right', true); } else { this.setVelocityX(0); this.anims.play('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
  11. 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.
  12. The PG https://playground.babylonjs.com/index.html#0LM7CJ#10 is based on the PhysicsEngine HowTo example https://playground.babylonjs.com/index.html#0LM7CJ#6 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?
  13. 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); this.game.physics.enable(name, 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(); } }
  14. 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 = this.map.createLayer("platforms") this.map.setCollisionBetween(1,50, true, "platforms") var tilesArray = this.platformsLayer.getTiles(0,0,this.game.world.width, this.game.world.height) 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") }
  15. 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 ...
  16. 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: Phaser.Physics.Arcade.Image.call(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?
  17. 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)?
  18. <!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`
  19. 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. http://labs.phaser.io/edit.html?src=src\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 https://github.com/photonstorm/phaser/tree/master/dist
  20. 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?
  21. Hello there, Is it possible to create destructible terrain in HTML5 and box2d Video examples : Box2d Destructable terrain.mov Box2d Destructable terrain 2.mov Any help in this direction would be much appreciated. Thanks Again
  22. 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?
  23. 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!
  24. 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
  25. 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)