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

  1. Hi Guys, I started a new repository at GitHub for explaining Game Physics for newbie game programmers with JavaScript examples. There aren't many example right now but I will add more as I get time. It would be really great if you could contribute some of your physics knowledge. I am no expert in Game Physics and that's why I need some help in making this possible for new GameDevs who are in need of this. As always suggestions are very much appreciated but just stick to the topic "Simple Physics Models". Thanks. http://bit.ly/UDkLD7 is the link to my repository
  2. It's even kinda funny to ask such a thing, but... Phaser.Physics.P2.Body class has two useful methods to convert points to local/global metrics (docs). For instance it's said [i][b]toWorldFrame(out, localPoint)[/b][/i]/* Transform a local point to world frame. */// out:Array - The vector to store the result in.// localPoint:Array - The input local vector.Ok, fine. I've created a new body with a (0.5,0.5) anchor, moved it to 100:100 px, then i try to find out what will be the (0,0) local body point in global coordinates - obviously the point is 100:100. Let's check: // create a spritevar s = game.add.sprite(0, 0, '');// position at 100:100s.x = s.y = 100;// enable p2 to create the bodygame.physics.p2.enable(s, true);// now try to find out the local 0,0 in world metrics// holds the global point (dunno why, but it's an array rather than Point)var v = [];// relative 0:0 point in global coordinates -- should be 100:100s.body.toWorldFrame(v, [0,0]);// traceconsole.error('result', v);// wtf is this?! O_o// result [-5, -5] Same with the toLocalFrame method. So: - what do these methods calculate?! O.o - are there properly working localToGlobal(p:Point) and globalToLocal(p:Point) methods in phaser or i should implement them myself?
  3. I'm trying to gain an understanding as to how setPhysicsLinkWith works and I must be missing something. Here's my sample code: http://www.babylonjs.com/playground/#1LXLMJ Why does ball2 not "link" to the bottom of ball1?
  4. I want two arcade physics bodies to single sprite, one is for horizontal collision and one is for vertical. can we do this? Advance thank you.
  5. I'm getting up-to-speed on developing with Babylon.js and I'm having a problem with physics simulations and initial rotation on a mesh: You'll notice that the box and the ball bounce off the air above the "ground." My expectation is that both the box and the ball would land on the surface of the ground. It works as expected if there is no initial rotation. The greater the rotation, the more obvious the problem. Here's how I'm rotating the ground: var ground = BABYLON.Mesh.CreateBox("ground", 10, scene);ground.rotate(BABYLON.Axis.Z, .3, BABYLON.Space.LOCAL);ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 0.4});If it helps, here's all the code I'm using to create the scene: var createPrototypeScene = function(engine) {var scene = new BABYLON.Scene(engine);var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 10, -40), scene);var light0 = new BABYLON.DirectionalLight("Omni", new BABYLON.Vector3(-2, -5, 2), scene);var light1 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(2, -5, -2), scene);camera.setTarget(new BABYLON.Vector3(0, 0, 0));scene.enablePhysics(null, new BABYLON.CannonJSPlugin());// Create the groundvar ground = BABYLON.Mesh.CreateBox("ground", 10, scene);ground.rotate(BABYLON.Axis.Z, .3, BABYLON.Space.LOCAL);ground.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:0, friction:0.5, restitution: 0.4});// Create the ballvar ball = BABYLON.Mesh.CreateSphere("ball", 16, 1, scene);ball.material = new BABYLON.StandardMaterial("ball", scene);ball.material.wireframe = true;ball.position = new BABYLON.Vector3(3, 20, 0);ball.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor, { mass: 5 });var box = BABYLON.Mesh.CreateBox("box", 3, scene);box.position = new BABYLON.Vector3(0, 15, 0);box.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass: 1});return scene;}Thanks!
  6. We want to show you one of our recent games called “Cyclop Physics”. It’s a physics-based puzzle game. The idea of the game is to place evil red and retarded green objects on the platforms of matching colors. You can change the form of the object (a ball into a box or vice versa) by taping on it. Due to the game’s nice and comic art and animation we suppose the “Cyclop Physics” will be a fun to play not only for adults but especially for kids. The game has 24 levels + the “sprint level”. In the “sprint” you are given all levels in a random order and the limited amount of time to pass them. It's a cross-platform game and it supports most screen resolutions. You can check it here. Can’t wait to hear what you think. Hope you’ll like it!
  7. Hello everybody! This is my second HTML5 game: Escape Them. Help the alien escape an evil organization by keeping him airborne for as long as possible. Smash into any enemy that stands in your way and knock them out of the sky. It was created using the Phaser framework and it uses p2 for the physics. Warning: features occasional explosions. You can play the game here: http://dl.dropboxusercontent.com/u/72677606/Escape%20Them/index.html More Details (My blog): http://badbeargames.blogspot.com/2014/05/escape-them-preview.html Thank you
  8. Hi all, I have a bit of weird behaviour in my code, while trying to optimize it. Setup: A level with a tilemap layer, with enemies and bombs. The enemies extend the Phaser.Sprite class. Arcade physics. Gravity is on. When a bomb explodes, it applies force to the enemies, pushing them away (both horizontally and vertically). The issue: When I use States update() function to check for collision, it works fine, the enemies are launched in the air (depending on proximity): //pseudo codeGameState.prototype.update = function(){ Phaser.Physics.Arcade.collide(enemiesGroup, layer);}Having a look at Phaser's source code, I want to optimize my code, and skip unnecesary object type checks. Because I know the object types of the stuff I want to check collision on, I use Sprite.update() function to check for collision. //pseudo codeEnemy.prototype.update = function(){ Phaser.Physics.Arcade.collideSpriteVsTilemapLayer(this, layer);}With this, the enemies are pushed only horizontally, which is the issue. In short, from the source code (physics/arcade/World.js, line 371), Phaser.Physics.Arcade.collide(object1, object2) checks the passed objects types and calls the coresponding function, in this case Phaser.Physics.Arcade.collideSpriteVsTilemapLayer(object1, object2). By order of internal Phaser's calling of functions, State.update() gets called first, then Sprite.update(), but I think the call order shouldn't have any effect. The reasons behind the optimization: I might have quite a lot of enemies at any given time (150-200), so I want the code to run without checking every enemy for the object type. Also, from OOP point of view, it's better to have the enemy itself check for collision, instead of the state. So, any idea on how can I have this optimization, or why is there a difference?
  9. So I'm working on a game that is just about complete and I'm using CocoonJS to wrap it up for Android. I noticed that when putting it on a Samsung Galaxy S4 that it does lag a bit. It's not too troublesome but I would like to remove this lag if at all possible. I have a strong feeling that it's coming from my physics calls because of the way my game is set up, so hopefully I can get some tips on how to better set things up. Currently my game has a character the rides along a set of teeth. As the character touches each tooth it becomes clean thus playing an animation. This continues indefinitely as per design of the game. Currently in the main update function there is this piece of code for handling the collision. for (var i = 0, length = this.teethGroup.length; i < length; i++) { this.game.physics.arcade.collide(this.bactoSurfer, this.teethGroup.getAt(i), this.cleanToothHandler, null, this);}The callback function simply plays an animation and updates the score. The tooth's body property is set to immovable and velocity to -350. However in order to stop the player from being pushed back I had to set it's velocity to 350. Is there a better way to handle this kind of collision? Also is there a way to have the player's character just sit on the moving teeth and still have the collision callback function go off without having to counter the teeth's velocity? My final question is what sort of performance issues should I look for in the physics portion of the game? Thanks in advance.
  10. Hi all, I'm struggling a bit to find a way to make a realistic explosion effect (physics, not visual). The situation is this: The game is a horizontal side-scrolling platformer. I have a player that's throwing grenades. On impact with a tile, the grenade explodes. I want all enemies (sprites) within the blast to be affected by a realistic circular blast wave, pushing the enemies away in relation to how close they were to the impact point. I have the impact vector (distance and angle from impact point), and I can calculate the impact force (closest - max force, further - less force) in relation to the blast radius, but so far I have no means to apply it to an enemy. Some ways I can think of: - push the enemy back by setting it's x,y, which is instantly, and not realistic - apply (add) negative/positive velocity to the enemy (which will be constant, and unrealistic) - create many concentric circles with center at the impact point, and over time degrade their velocity effect to 0, while having a onOverlap callback adding the velocity effect to the enemy sprite - create a circle at the explosion point, which will expand by time, and push out the sprites by collision (maybe add bounce to the enemies). But unless I use P2 physics, this will be unrealistic - using - Phaser.Physics.Arcade.accelerateToObject(enemy, blastOrigin, -500, 0, 0) - Phaser.Physics.Arcade.accelerateToXY(enemy, PointFromForce, 500, 0, 0) - Phaser.Physics.Arcade.moveToObject(enemy, blastOrigin, -500, 0, 0) - Phaser.Physics.Arcade.moveToXY(enemy, PointFromForce, 500, 0, 0) but with all these methods the enemy continues to move indefinitely, and I don't have a way to stop it What I'm trying to achieve is like 2 sprites colliding (with bounce), with a finite stop point, or a planet with inverse gravity (pushing bodies away). Best aproach I can think of at the moment is to have something like deccelerateToXY(Point) function, which will stop the sprite when the point is reached. At the moment I'm using Arcade physics, but if this can be done with P2, I will switch. Also, note that, at the moment, the enemies don't move by themself, but when I'm done with implementing the AI, they will move (try to follow the player, run away from player, move independently ...), which will bring additional complications. Any ideas and help are appreciated. P.S. Can I mix Arcade and P2 physics?
  11. Hi. I've just been profiling my game and it has been *awfully* slow to cleanup a part of a tilemap. There wasn't any indication of why it would be slow; 20x20 was snappy. 100x100 was a nightmare. And I was updating 390 tiles. Now I'm not using physics. Tilemap code updates all layers when things change so it was a loop of 100x100x390 updates in TileMap.calculateFaces. Unsure if I was doing something wrong or some such, but I don't think this is a desired functionality. I'd say - do this at most once per frame. What I did was hack it by adding "return; //collision isn't used here." in the first line. I do my collisions outside of phaser (I anyway need to store my map data and objects logic for load/save) so that's probably why this was not needed. Anyway - It'd be nice to make it simple to update multiple layers and keep the calculateFaces from firing. Maybe something like: TileMap.preventRecalculate(doPrevent); and if it's prevented and changed, you just mark it for update. Simple, I think. Thanks for the freat framework, Tim.
  12. Hello, I have 2 floors, one above the other. What is the best way to have the player move between the the floors? For example when the down key is pressed I'd like the player to move to the floor below. Likewise when the up key is pressed I'd like the player to move to the floor above. Please see attached image. I was thinking about disabling/enabling the floor. If this is the best approach how do I this using Phaser? Thanks, Gar
  13. I see that a flat terrain generated using CreateGround stops my object from falling through but terrain generated using CreateGroundFromHeightMap objects simply fall through using both basic phsyics and cannon.js which leads me to wonder if heightmap terrain even supports physics yet or not.
  14. How do I simply set an x, y coordinate on an arcade body? Specifically, I'm trying to set the starting position of a player after the sprite is created and physics enabled, but before there is a physics update. When I do so as below, the body ignores the new setting and opens with the sprite at the initial dummy coordinates. I have arranged my code like this: // Map inherits from Tilemap and creates all of the layersvar map = new Map(this.game, 'map'); // Player inherits from Sprite// 0, 0 is the initial coordinate// the constructor enables physics on the bodyvar player = new Player(this.game, 0, 0, 1);// This is so that map can insert the player into the proper// group index and location.map.addPlayer(player);in Map I have:function addPlayer(player){this.game.world.addAt(player, this.PLAYER_LAYER);player.body.moves = false; // <-- doesn't seem to matter whether this is set or notplayer.body.x = this.START_X;player.body.y = this.START_Y;player.body.reset(this.START_X,this.START_Y); // <-- doesn't matter whether I set it this way or not}How can I move the sprite to the proper starting coordinates?
  15. Hi all, I'm very very new to Phaser and game dev in general. To teach myself the basics, I've been working on a few different prototypes that implement various physics mechanics, or address some other specific challenge. Recently I created a prototype in which a rogue-like char has to avoid a few moving columns and get to a "win" sprite (...physics.arcade.overlap) to finish the level. To make things more interesting I tried to implement some tiles where, on ...arcade.overlap the tiles would manipulate the players movement - essentially creating a water-like current, so that the players movement was lightly restricted in one direction, but enhanced in the other direction. Here's the code: Under create(): // configure the water blocks waters = game.add.group(); waters.enableBody = true; water1 = waters.create(0, 96, 'water'); water2 = waters.create(game.world.width - 256, 224, 'water'); water1.body.immovable = true; water2.body.immovable = true;Under update(): game.physics.arcade.overlap(player,water1, water1Flow, null, this); game.physics.arcade.overlap(player,water2, water2Flow, null, this);water1Flow (since the two functions are nearly identical): function water1Flow() { player.body.velocity.x = 100;}I expected that this would have an impact on the player sprite's movement, but it hasn't done ANYTHING. I put a "console.log(player.body.velocity.x);" line in the function, and it showed that the velocity was 100, but in actual gameplay, that doesn't seem to be the case. Any help or ideas would be greatly appreciated! Thanks
  16. Hi all, I'm looking into Ninja physics and specifically the tilemap example. I'm curious as to how the points on the map are defined, I'm assuming it's with the following line var slopeMap = { '32': 1, '77': 1, '95': 2, '36': 3, '137': 3, '140': 2 };However there's no description as to where these numbers come from, are they generated/set using Tiled and if so how should I be going about this. Also, is it possible to detect when the ball in the above example hits part of the map/tiles? What I'm wanting to do is create a game where the player is a rocket going left to right inside a cave which would be a pointy map/land above and below the player, would this be the best route for implementing such a game. Thanks, Martin
  17. Hey guys, I apologize for my first post being a cry for help.. but I'm in a bit of a time crunch.. I'm hoping to throw together a Lunar Lander type game but use accelerometer for the controls. After some searching and reading I'm worried that the physics system wont be able to achieve what I'm after ( I can't math anything together :| ) This will be my first Phaser project, but I've done a little with Box2d and Pixi so I think I understand how to tie bodies together and all that fun stuff.. Basically I want to attach the "rocket engine" to a rocket, but have them both rotate based on the accelerometer's input. If your ship’s nose is tilted to the right, the boost would be applied below you and a little to the left.. depending on the overall angle of the ship. I started with this fella's code: http://www.html5gamedevs.com/topic/2904-feedback-for-my-first-lines-of-code-moon-lander-game/?hl=moon Was thrown by the angle maybe becoming an issue here: https://play.google.com/store/apps/details?id=sk.flashdev.android.moonlander&hl=en Insanely hard version of the game, but no accelerometers: http://moonlander.seb.ly/ And this guy beat me to the punch entirely: https://play.google.com/store/apps/details?id=sk.flashdev.android.moonlander&hl=en I’m hoping their is something I’m missing with the setup of bodies, or perhaps some fancy math that can be applied to both velocity x and velocity y that correlates to the sprite angle. Bonus points for being able to have this ship bounce off another players ship (while respecting the shape of the ship in its current rotation) Any help or direction is awesome! Thanks!
  18. I've been experimenting with Phaser a bit the past few days. I've encountered a problem with sprites not overlapping with tilemaps. Two captures follow with slightly different settings in play. 1) 2) The robot near the center is a sprite, shooting other sprites. It has moved hard up into the corner of a couple walls defined by a tilemap, such that when the bullets appear they are already inside colliding tilemap tiles. I would expect the bullets to overlap and be killed by my handler. Note that they do collide otherwise, so there's no basic problem here of improper collision flags or such. The green boxes are the body debug draw, showing that they're in the right places. This is using arcade physics, Phaser 2.0.5. I can't find any "reasonable" setting of TILE_BIAS, tilePadding on the bullets, velocities, etc., that prevents this problem in all cases. At first I thought the bullets were simply moving too fast, hence their velocity is much slowed down in the second capture. In both cases though they're clearly squarely in the middle of the colliding tiles for several cycles, but still no overlap. Note in the first example that the angles work out such that the left shot is probably starting right on the edge of a tile and is properly detected after it first enters the tile (hence the slight flickering). Currently I have TILE_BIAS set to 40 and the following creation code on the bullets: this.pBullets.createMultiple(40, "player-shot"); this.pBullets.setAll('anchor.x', 0.9); this.pBullets.setAll('anchor.y', 0.5); this.pBullets.setAll('pivot.x', -30); this.pBullets.setAll('body.width', 4); this.pBullets.setAll('body.height', 4); this.pBullets.setAll('body.tilePadding.x', 16); this.pBullets.setAll('body.tilePadding.y', 16);The tilemap is created as such: this.map = this.game.add.tilemap("map", 32, 32); this.map.addTilesetImage("tiles"); this.map.setCollisionBetween(0, 10); this.map.setCollisionBetween(28, 38); this.map.setCollisionBetween(56, 67); this.ground = this.map.createLayer(0);The collision is called as such: this.physics.arcade.overlap(this.pBullets, this.ground, this.bulletHitWall, null, this);And the overlap callback is: bulletHitWall: function(bullet, wall) { bullet.kill(); },Any thoughts? Thanks
  19. I am trying to build a similar game to gemmatch http://phaser.io/examples/_site/view_full.html?d=games&f=gemmatch.js&t=gemmatch In the example it creates tweens for each gem movement. Is it a good idea to do this every move, or should i use physics instead?
  20. Hi all I'm crafting my little space game with ships and other stuff using Phaser - http://gregorl.github.io/spaceships-with-lasers/ I recently created some collision maps for asteroids using PhysicsEditor - it was one polygon per sprite until now. Now I need to somehow apply the player's ship polygons to the right frame of animated ship. This is my loading code: https://github.com/gregorl/spaceships-with-lasers/blob/master/src/js/preloader.js . As you can see I use game.load.spritesheet for ship's sprites. And here's the player's creation logic: https://github.com/gregorl/spaceships-with-lasers/blob/master/src/js/game/player.js The sprite is animated, but its body is not. Could someone point me the right direction? How do I animate sprite's body? How do I apply the shapes to appropriate frames of the spritesheet? Perhaps I misused PhysicsEditor, when preparing the polygons for each ship's frame? I am asking this, as I was not able to find related topic or Phaser example to follow.
  21. hullo, our latest game has just gone live on agame.com. Really quite happy with how the physics worked out in the end and of course pixi is as blazingly fast and awesome as ever. hope you all like it http://m.agame.com/games/action/super_awesome_truck thanks Chris
  22. Hey all, Just a quick heads up to share an odd solution to a problem that had me tearing my head out for a couple of days, thought it may come in handy for anyone else in the same boat. While working on a game where I was using P2 physics to detect a collision event between 2 physics bodies, I found that whenever the target sprite was rotated further than a certain amount all of my collision events would silently fail. I spent AGES trying different collision methods and none of them worked, when trying to implement a hack-ish workaround that I found on the forums (can't remember where) I realised that my collisions were now working fine, even though the method I was using returned something to the effect of "this doesn't work". Long story short - I found that by resetting a physics body's AABB data after every change in rotation made the collision events work again: //attackingThing.body.onBeginContact.add(reportSomething, this);//function rotateThing() { // thing.rotation += 1; // reportSomething fails unless you do this thing.body.data.updateAABB();}If anyone can enlighten me as to what/why/how this works, that'd be awesome. Phase on, dudes! OFM
  23. Hi all. I am trying to learn to use the physics engines (and teaching kids to use them at the same time). I’m looking for a quick reference to the engines, with a column on the left for each common task and in three columns on the right how to do them in each engine. Or other discussions on how to keep everything straight while learning them. Thanks. Dave Briccetti davebsoft.com
  24. **Solved! **cannon.js does not like 0 height object. I suggest you to use a box with scaling.y = 0.01 instead of a plane for your ground **Code has been updated Does anyone have a clone why these meshes are sometime falling through the ground plane and other times they are not? Do is have to do with my "setPhysicsState" settings or something else? http://filmsbykris.com/scripts/Game-Basics/BabylonJS/importing/clone_1.html Thanks in advance for any help.
  25. Copied from https://github.com/photonstorm/phaser/issues/870 I have found that for Arcade and P2, if a body falls due to gravity and collides with anything (tilemap layer or world boundary), it never fully comes to rest. Instead it keeps bouncing imperceptibly. You cannot see this, the body appears to be at rest on screen. However checking body.velocity.y or body.speed will show it alternating rapidly. I've done a plunk demonstrating this. Watch the velocity.y and body.speed variables in the debug. http://plnkr.co/edit/QRjgwj?p=preview From looking at the Phaser source, it looks as if velocity.y is always recalculated with gravity and there's not an easy way to check at that point if the body is blocked. Any advice?