Jump to content

Search the Community

Showing results for tags 'body'.

  • 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 Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

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

  1. Hola hola, So I am working on a 2D basketball game. I am using 2 small sprites (with circular physics bodies) on each side of the basket rim for collision detection with the ball. I parented the 2 sprites to the backboard so I could move them all together (as shown in the child sprite example). I turned on the debug draw for the physics bodies and found the 2 bodies were not in the same position as the sprites. //Load net sprite this.net = this.game.add.sprite(this.game.world.centerX, 200, 'net'); this.net.anchor.setTo(0.5); //Add hoop children markers this.leftMarker = this.net.addChild(this.game.make.sprite(-66, 60, 'marker')); this.leftMarker.anchor.setTo(0.5); this.rightMarker = this.net.addChild(this.game.make.sprite(66, 60, 'marker')); this.rightMarker.anchor.setTo(0.5); I parent them like so.. but my physics bodies don't act as if they are parented. They should be at the same position as the sprite, but instead they are (-66, 60) and (66, 60) from the top left corner (0, 0) instead of (-66, 60) and (66, 60) from the parents position (world center x, 200). You can see the attached image as an example. Is there something I am missing? Is this the way it's supposed to be? Can I somehow update the physics bodies to line up with the sprites easily?
  2. So I am working on my just general knowledge of how phaser works, I have only done two tutorials. But I think I have a decent grasp on it so far. But I am running into a little problem, I am trying to use the Follower object, so that I don't have to create the vec2 and attach it, but I don't seem to understand the documentation or what it means by "If this Game Object is enabled for physics then this property will contain a reference to a Physics Body." I have scoured the docs for hours. I see how to 'enable' in arcade physics but I cannot find any reference to how with impact physics. I am able to create a body object, and assign it to the game object, as well as assign the the game object to the body, but they do not move in tandem. in fact the body does not move at all. P.S. This is not the only bug, when converting from matter.js to impact.js physics my logic on pausing player movement when the dialog modal broke. but one problem at a time.. P.P.S I know its not the best code //SHIVA path3 = new Phaser.Curves.Path(550, 450); path3.lineTo(450, 450); path3.lineTo(450, 505); path3.lineTo(550, 505); path3.lineTo(550, 450); path3.lineTo(450, 450); shiva = this.add.follower(path3, 550, 450, 'shiva'); //Phaser.GameObjects.BuildGameObject(this, Phaser.GameObjects.PathFollower) //this.game.physics.enable(shiva, impact); shivaBody = this.impact.add.body(550, 450, 16, 12); //TRYING DIFFERENT WAS TO SET BODY //shivaBody.setOffset(550, 450, 16, 12); shiva.body = shivaBody; shivaBody.setGameObject(shiva); shiva.name = "shiva"; shiva.setRotation(); shiva.depth = 30; //ALT WAY TO GET NAME //shiva.name = "shiva"; shiva.setData(npc, true); shiva.setData("name", "shiva"); npcBodies[2] = shivaBody; npcs.add(shiva); shiva.startFollow({ ease: 'Linear', duration:6000, yoyo:true, repeat: -1, _delay: 200, delay: 100 }); P.P.P.S I also tried this.physics.world.enable(shiva); this.impact.world.enable(shiva); dialog_plugin.js game.js index.html city.json
  3. I would like to increase a sprite's hit area so that its easier to tap on it on mobile. I would like to keep its body the same size however as there are collisions in the game that depend on it. How can I accomplish this? I tried paddle.body.setSize(500, 200, 0, 0); but this seems to increase the body size, screwing up collisions. Thanks!
  4. hi all, I have a problem about the p2 body and sprite positon when I enable a p2 body to a sprite, I use fish.body.setRectangle(fish.width, fish.height); to set the body shape, but the position of body is far away from the sprite, anyone know what is the problem? thx
  5. I'm struggling with giving a Geom a Matter body, or with updating graphics according to matter bodies movement. I'm trying looping through all my Geoms, created from all my matter bodies, and then updating each with the position of the matter body and drawing it in to the graphics, but the results performance is really bad. Can anyone please provide me with an example? I found none at labs.phaser.io Thanks!
  6. 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?
  7. Hey guys, I'm new to phaser and I'm not quite sure if this is a bug or a mistake of myself. In this code if the player has a circle as his body and if he is colliding with one of this obstacles he won't get separated as it is described in the phaser documentation. So if you move up and collide with the obstacle the console starts printing out true even if you stop moving. In addition to that if you walk against an edge of the obstacle the player gets stuck on it and can't get away of that. I'm confused because this doesn't happen if the players body is an rectangle. Does anybody have an idea? var game = new Phaser.Game(600, 600, Phaser.AUTO, "", {preload: preload, create: create, update: update}); var player; var cursors; var obstacles; function preload(){ game.load.image("robot", "player.png", 32, 48); game.load.image("obstacle", "box.png"); } function create(){ player = game.add.sprite(game.world.centerX, game.world.centerY + 200, "robot", 5); game.stage.backgroundColor = 'rgb(239, 228, 176)'; game.physics.arcade.enable(player); player.body.setCircle(player.width/2);// player don`t get seperated in the collide function //player.body.setSize(player.width * 0.8, player.height*0.8,player.width * 0.1, player.height*0.1 ); //player get seperated in the collide function player.anchor.set(0.5); player.angle = -90; cursors = game.input.keyboard.createCursorKeys(); obstacles = game.add.group(); game.physics.arcade.enable(obstacles); obstacles.enableBody = true; obstacles.create(game.world.centerX, game.world.centerY - 200, 'obstacle'); obstacles.create(game.world.centerX - 190, game.world.centerY - 200, 'obstacle'); obstacles.create(game.world.centerX + 150, game.world.centerY - 100, 'obstacle'); obstacles.create(game.world.centerX - 130, game.world.centerY, 'obstacle'); obstacles.create(game.world.centerX - 230, game.world.centerY, 'obstacle'); obstacles.setAll('body.immovable', 'true'); obstacles.setAll('anchor.x', '0.5'); obstacles.setAll('anchor.y', '0.5'); } function update(){ game.debug.body(player); obstacles.forEach(function(item) { game.debug.body(item); }); if (cursors.up.isDown) { game.physics.arcade.velocityFromAngle(player.angle, 200, player.body.velocity); } else { player.body.velocity.set(0); } if (cursors.left.isDown) { player.body.angularVelocity = -300; } else { if (cursors.right.isDown) { player.body.angularVelocity = 300; } else { player.body.angularVelocity = 0; } } game.physics.arcade.collide(player,obstacles,(p1,en)=>{ console.log(true); }, null, this); } cheers landa
  8. So I have been searching a solution for this for 2 days now. I have a character with physics body. This character has sprites attached to it with addChild(). Arms, sword, cloak, range indicator. Range indicator also has a body (only used as sensor/trigger ). However as I found out addChild doesn't work on physics bodies. Sprites move together but I can get Range Indicator's body to move with them. It pretty much sits in the corner. Since addChild() is no go for physics bodies, is there anything else I can use with this? Really trying to avoid writing a custom function to make the body follow me but running out of options here. EDIT: Found a workaround for weird child behaviour with bodies. Added another invisible sprite and made it child to my body. this.rangePositioner = game.add.sprite(0, 0, 'rangeBlack'); this.rangePositioner.anchor.set(0.5); this.rangePositioner.pivot.set(0, 40); this.addChild(this.rangePositioner); Take its world position with rangePositioner.world ( rangePositioner.position returns 0 ) then set it to my child body.position. I had to dig for some time before I realized sprite.world returns a point. I would expect it to be named something like worldPoint. Anyways I hope this helps someone.
  9. I just upgraded to Phaser 2.9.3, since then I get a strange behavior. 1. I press Left / Right to change the Sprite's velocity (x). // See update method 2. Sprite has enabled Physics, World.gravity is 2000 // See in create method 3. But the Sprite instead of moving left (negative velocity.x) moves upwards // See attached gif What I figured out till yet: - velocity.y turn to NaN by colliding with a collisionGroup . - velocity.y stays NaN, even if the character moves into the air. (whyever it moves into air..) There is nothing else going on. I tested this as a test-case, not inside my game, to be sure I'm not messing something up. create method: super(state.game, x, y, 'minions'); this.level = state; this.anchor.setTo(0.5); this.game.physics.arcade.enable(this); this.game.add.existing(this); this.body.bounce.set(0.5); this.body.setSize(45, 110, 80, 45) update method: if(this.controls.on("left")) { this.body.velocity.x = -500; this.animations.play('walk'); } else if(this.controls.on("right")) { this.body.velocity.x = 500; this.animations.play('walk'); } Anyone have a clue why this happens? Thanks in advance.
  10. Hello, i am again... i have a realy noob question but cant find an answer. Since i playing with this Playground i try to figure out how i can get the position of the car (mesh = carBody ?) Im not successful. Line 42 - 44 scene.registerBeforeRender(function(){ console.log("Poisition", carBody.position); }); The only thing that changes is when i turning the steering wheel. Nothing about the position on the ground... I tought the carBody "merge" all meshes into one and move them around with them. So that the positions property on child meshes a relative to the parent mesh. I dont get it...
  11. I'm trying to add a collision box to a sword swing. I'm using one sprite for the swing and rotating it 0, 90, 180, 270 degrees, depending on direction. As physics bodies are not affected by their sprite's rotation, I'm using body.setSize(width, height, offsetX, offsetY) to move the collision area depending on direction. Problem: It seems that (width, height) updates earlier than (offsetX, offsetY), or that the new offset is delayed one update. This leads to the hitbox reaching beyond the player's attack range. How can I avoid this? One way to easily test this is by calling sprite.body.setSize( <randomX>, <randomY>, <randomOffsetX>, <randomOffsetY> ). The sprite's angle does not affect this. ^ The collision area updates its size first, and later snaps to its new offset. ^ The sword sprite, 48x48. Red box indicates where the body's collision area should be.
  12. I see the docs of the Body class http://phaser.io/docs/2.6.2/Phaser.Physics.Arcade.Body.html But i am not sure which would be the right property to change. I have two balloons falling down and they might both at the same time or one after the other, hit my rectangle. The problem is, both objects stop moving after they hit the rectangle. i am sure this has to do something with physics. As if the vertical(y coordinate) velocity gets set to 0 when they hit the rectangle. Here is a sample code: graphics = si.gameObject.add.sprite(boxX, boxY, si.ImageAssetKeys.BALLOON_ANIM_ATLAS, 0); floatingAnim = graphics.animations.add('floating', si.GraphicsUtility.getFloatingAnimArray(), 30, true); splashAnim = graphics.animations.add('splash', si.GraphicsUtility.getSplashAnimArray(), 30, false); splashAnim.onComplete.add(si.LetterBox.splashComplete, this); graphics.animations.play('floating'); balloon.graphics = graphics; balloon.graphics.anchor.setTo(0.5, 0.5); balloon.graphics.body.checkCollision.up = false; balloon.graphics.body.checkCollision.left = false; balloon.graphics.body.checkCollision.right = false; balloon.graphics.body.checkCollision.down = true; balloon.graphics.body.velocity.y = velocity; balloon.graphics.allowGravity = false; balloon.graphics.allowRotation = false; Which body property should I change to prevent the stop in movement of balloons?
  13. http://danecekpilar.borec.cz/ Hi guys. during the development in Phaser i found out, that there is no simple online editor for Making Physics bodies for P2 physics in Phaser. So i came up with an simple idea. To do a simple online body editor to make json files for Phaser. I know its super simple and it could do much more things as other desktop body editors can do, but when you want just simple body in two minutes, i think its a good way. I took me less than two hour to do it, so dont judge it for bad appearance and not efficient solutions for the algorithm. Maybe ill do things like more bodies in one json file, or auto edge-tracer adn stuff like that, but fell free to comment and come up with your ideas to improve it for the future. So please, if have have anything to say to this, comment below, i would be pleased. http://danecekpilar.borec.cz
  14. I'm new to Phasor and using it to make a little game for my son with a firetruck driving around and spraying water to put out fires. When the space bar is pressed, the game creates individual water drop sprites coming from the truck with gravity turned on. I give the water drop velocity a slightly random component to make it spread out and not all follow a single parabola. There is a timed event to destroy each water drop. Here is a code snippet creating a water drop that is shooting to the right. drop = waterdrops.create(truck.body.position.x + TRUCK_SIZE1_X/2, truck.body.position.y - 20, 'waterdrop'); drop.frame = 0; drop.body.gravity.y = 300; drop.body.velocity.y = -100 + randn()*20 + truck.body.velocity.y/2; drop.body.velocity.x = 100 + randn()*20 + truck.body.velocity.x/2; game.time.events.add(WATERDROP_TIME, destroyDrop, this, drop); I fiddled around with different numbers until it looked like a nice spray of water coming out and hitting the ground. This works great when developing on my Macbook Air. However, the really weird issue is that when I run it on my Windows 7 machine the water only goes half as far before being destroyed. I tried doubling the delay time and this made it work well on windows 7 but then on the Macbook the water goes way too far. I also notice that the truck itself seems to go slower. It seems to me that if the body.velocity and body.acceleration values are scaled differently on each machine. My first though was that maybe it has to do with screen resolution, but thinking about it further that doesn't seem to make sense. So, why is there a difference in water drop behavior between the two platforms? Also, is there a better way to do what I'm trying to do here? As I said, I'm new to Phasor and this is just what I came up with after reading a few tutorials and looking at other examples. The game as it stands is hosted here -> http://drnx1m5jr5iqt.cloudfront.net/ Thanks! Ben ** UPDATE I ran the game on another Windows 7 machine and it works okay. So the problem seems to be with my older Windows 7 Machine. Could this be an issue of client side CPU processing capability? Does Phaser adjust frame rate to deal with slower computers?
  15. Hi, in my render function, I have the following: render: function() { this.game.debug.body(this.player); this.game.debug.body(this.redMonstarsGroup); }, Now, the player, has a little green box around him, however the monster (or the group of monsters) has nothing and I get a warning: " gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);" HOW TO I GET A LITTLE GREEN DEBUG BODY ON A GROUP OF OBJECTS?
  16. HI Been going through the Book Discover Phaser, but are stuck with this bit of code: The jump functionality on the player somehow doe's not work. When I console.log the body.touching object, I can see, that body.touching.down does not turn true, when the player hit's the a platform. Furthermore, the cursor.up is detected when I leave out this bit of code: '&& this.player.body.touching.down', but somehow does not function, when the code is as in the Quote. Any Ideas to what I should be looking for? Thanks.
  17. Hello, I have searched a solution for a problem for long time and didn't found, if someone have some ideas I am taking all x) did someone know if it's possible to rotate a group of bodies around an anchor point, I set some bodies for invisble walls and my objective is to turn them around by 90° around an anchor point, I know It must be not very comprehensive so I set up an Image to explain myself. In the screen, I have 2 bodies and I want them to turn around the red dot what must be my anchor point, I know it's impossible in arcade so I tried in P2 physics and impossible to found any solution :/ Thanks for reading, feel free to leave a feedback
  18. Hey guys, hope you're having a great time. And I have a little problem you may be able to help me with. I'm making sort of RTS and there are lots of units marching to each other and killing each other. The problem is, they are stepping onto each other, and kind of pushing each other, and sometimes even jumping someplaces. This looks weird. Watch this video and you will understand what I'm talking about (I'm using Warcraft 2 sprites just for testing purposes, and also because they are great). https://www.youtube.com/watch?v=6htpVG8Shyc A little more details: I'm using Arcade physics. All units are objects of the same class, derived from Phaser.Sprite. All of them have a circle body, anchor set to 0.5 (if if matters), and are moving using velocity (before that I was modifying their poistions manually but with the same result). Units belong to 2 different groups, each group is collided with self and other group - so they won't walk through each other. What I want is that units would be standing still and no one could move them, not to mention these weird jumps. Is there some common techinque for handling this, do I miss something? Thank you in advance.
  19. mm

    Sprite body anchor

    Hello, there is a small difference between the sprite body anchor between phaser 2.6 and older versions. In previous versions the body will anchor with the sprite anchor, meaning that if you set the sprite anchor to 0.5 in both axis the body stayed in the center of the sprite, changing the body size would keep it in centre, in the newer version the body is always anchored to the top left of the sprite regardless the anchor of the sprite. Is this behaviour intended? Just wondering if I should re-center my sprites bodies or if this will change to the old behaviour. Thanks.
  20. Hey guys, I am developing this draft game demo and I need some advice/ feedback on some tips to make the collision a bit better. I'm using loadPolygon to load a custom body shapes for this sprite object and responding to collisions using onBeginContact to applyImpulse to the ball on a SPACEKEY.onDown The following is the code player.body.collides(ballCollisonGroup, this.headerBall, player) headerBall(bodyA, bodyB, shapeA, shapeB, equation) { let duration = 10; let localX = equation[0].contactPointA[0]; let localY = equation[0].contactPointA[1]; let forceX = 0.12 * this.headMass; let forceY = 0.8 * this.headMass; if(this.headerKey.isDown) // only if see is down apply additional force { duration = Math.min(this.headerKey.duration, 500); // apply time based on how long key pressed forceY = (1 * this.headMass).toFixed(2); // apply force of 1 velocity x mass of head (.53) forceX = (1 * this.headMass).toFixed(2); let impulse = [(forceX * duration), (forceY * duration )]; // calculate impulse bodyA.applyImpulse(impulse, localX, localY ); // apply it to ball } } I'm not sure if I am doing it right as I am not verse in Math Physics but i would like some feedback on the following: - Is my formula accuarate? Can I set varying impulses based on the contact shape? There is a sort of glitch if the ball comes into contact with his shoes and the ball ends up in the middle of his body which gets stuck. How can I avoid this? The key down condition seems to be glitchy is there anyway to make this a bit more "safe" to detect and capture? I need to apply some force to the ball ONLY when the space key is pressed. Thank you in advance for your feedback.
  21. Hey. Me again. I'm trying to figure out why my randomly placed platforms for my platform game won't be immovable. I've included the physics and enableBody to the group.. this._platforms = game.add.group();this._platforms.enableBody = true;game.physics.enable(this._platforms, Phaser.Physics.ARCADE);this._platforms.body.immovable = true; The player lands on the platform and the platform goes down with the player, both top/bottom and left/right. I get this error: Uncaught TypeError: Cannot set property 'immovable' of undefined Thanks in advance!
  22. I'm trying to make a prototype for a RPG game, I managed to make the drive, but I can't do the collision, can help? I have the ' background ' layer, that would be my floor, the 'colisao', where I keep all objects that the player will collide, as walls, and finally the 'coletaveis', where the items that the player can interact. Follow my code level 1: Not even the collision with the edge of the screen is working, can anyone help me? game.zip
  23. Hey everyone, I stepped upon an interesting thing or self induced bug that seems to be happening whilst using Arcade Physics for an infinite runner. It's pretty rough around the edges, more of a proof of concept than anything else, but basically in the update function I'm doing a couple of things. First of all, the ground is a group of child sprites, each ones velocity gets nudged left per update cycle: this.ground.children.forEach(function(c) { c.body.velocity.x = -this.RUN_SPEED; }, this); Then, I check to see if any of those children have gone off screen to the left (child.body.right < 0) for example. Once that's done, I then reset that child back to the right hand side of the screen like so: child.reset(this.game.width, child.y); In between all that I just do a couple of checks to make sure none of them overlap, by using this (it also makes sure we don't try to place anything else whilst this particular piece is still leaving the right-hand area: this.ground.children.find(function(child){ return child.x < this.game.width && child.x + child.width > this.game.width || child.x >= this.game.width; }, this); Now the main problem I'm having is that there seems to be a gap between each one of the sprites when they've been resetted and are following the one that came before hand. What I find interesting is that if I set the velocity to 256, the gap between each sprite seems to be exactly 12 pixels in width. If I drop it to 128, then it drops to 6 pixels in width. I'm curious as to how the numbers might correlate, or, is there something that happens in the physics step that's making the gap outside of the main update loop? It's a bit of a weird problem, and as said earlier, it's probably just down to poor implementation. I've attached the script file if you'd fancy a perusal also. Thanks for your time everyone, take care! IFPlay.js
  24. Hello. I was curious about the system implemented in some games, in this case applied to 2d only. I am talking about the creation a character body by drawing. Can that be applied to Phaser? An simple example would be something like simply drawing a 2D polygon with a "virtual marker" and then that draw would become a phyics body ( probably getting the borders of the draw and setting making a sprite out of it). I suppose I had to implement a way for the user to draw, then get the draw as image, somehow set its borders as I previously said and then load the sprite to the game. Am I thinking correctly? Can someone clarify me?
  25. Hi, just upgraded from phaser 2.4.4 to 2.6.2 and I'm having trouble with sprites bodies. My sprites are set to an anchor of x 0.5 and y 0.5, the body was also being set at that position on 2.4.4 version but after updating the body doesn't change position when changing the anchor. Is there any way to move the sprite body to the center of the sprite? Thanks.
×
×
  • Create New...