Search the Community

Showing results for tags 'velocity'.



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 54 results

  1. Hello & Thanks : I am having trouble getting bullets to go : I get error :Uncaught TypeError: Cannot read property 'velocity' of undefined m-vertical-collision.js:124 Pls , what do I need to make this puppy go ? Thanks
  2. Hello everybody ! I'm trying to build some slope and non-regular tiles but i have a lot of problem with collision. The main problem is that when I use moveRight()/moveLeft() on a slope (in this case, just a simple body) and I stop at the middle of the tile, my player just jump like that : On the other case, when I from the top of the tile to the left, my player just fly in the air and slowly land. I tried to tweak a bit the material by setting friction and removed restitution but it don't really change. Maybe it could work if I put a huge amount of gravity but then it will influence other part of the game (like jumping). I have also tried to add a sensor (simple circle) just below the sprite so I could set the x/y velocity at zero when the sensor is in contact with the ground. This is working well but it's not working at all when i'm trying to go down the slope. Basically it moves one px left, set velocity to 0, fall one px (cause of the gravity). move one px left and etc... This is the code if you want to reproduce the problem (I'm stuck with this for many days D:) : create() { this.playerMaterial = this.game.physics.p2.createMaterial() this.tileMaterial = this.game.physics.p2.createMaterial() this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.gravity.y = 400 this.player = this.game.add.sprite(40,40, 'player', 1) this.tile = this.game.add.sprite(80, 272, 'player') this.tile.visible = false this.game.physics.p2.enable([this.player, this.tile]) this.player.body.clearShapes() this.player.body.addRectangle(0, 40, 0, 0) this.player.body.debug = true this.player.body.fixedRotation = true this.player.body.setMaterial(this.playerMaterial) this.player.body.mass = 1.5 this.tile.body.clearShapes() this.tile.body.addPolygon( {} , 0,29, 0,40 , 50, 40 , 50, 0 ) this.tile.body.debug = true this.tile.body.static = true this.tile.body.setMaterial(this.tileMaterial) this.cursors = this.game.input.keyboard.createCursorKeys() this.jumpButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR) let contactMaterial = this.game.physics.p2.createContactMaterial(this.playerMaterial, this.tileMaterial) contactMaterial.friction = 1 contactMaterial.restitution = 0 contactMaterial.frictionRelaxation = 3; contactMaterial.surfaceVelocity = 0 contactMaterial.frictionStiffness = 1e7; contactMaterial.stiffness = 1e7; } update() { if (this.cursors.left.isDown) { this.player.body.moveLeft(200); } else if (this.cursors.right.isDown) { this.player.body.moveRight(200); } else { this.player.body.velocity.x = 0; } if (this.jumpButton.isDown) { this.player.body.moveUp(100); } } So, any idea how can I resolve this problem ? I'm a bit lost. Thanks !
  3. Took me forever to figure this out so wanted to share so someone else doesn't have to take forever to figure this out! If you load in a R.U.B.E. generated Box2d scene, setting body.velocity.x or body.velocity.y will not work, nor will body.moveLeft(n), body.moveRight(n), body.moveUp(n) and body.moveDown(n). You have to set body.data.m_linearVelocity.x and body.data.m_linearVelocity.y instead.
  4. Hi everyone, I'm developing a side scrolling mobile game for fun in my spare time. The objective is to direct a flying bee, who moves continuously to the right, between sets of honeycombs. If the player touches the honeycombs, they lose. It's effectively a replica of flappy bird. I'm trying to implement an incremental increase in velocity so the game gets harder the longer you play. - I've created a group (honeycombs) and added physics to the group - Created 20 honeycombs - Got the first dead honeycomb of our group - Set the new position of the honeycomb - Added velocity to the honeycombs to make it move left (creates the illusion of the bee flying): pipe.body.velocity.x = -200; - Kill the honeycombs when they're no longer visible - Picked where the hole will be - Added six honeycombs - Run function to add honeycombs every 1.5 seconds I'm aware I could have two different game states (easy and hard) with different velocities but I'd rather have it increase over time. Any help would be hugely appreciated! Thanks!
  5. Hello. I've noticed that many people have a similar problem. If sprite has physics enabled: how to change its position without interfering with physics system? It's a famous 'fly off the screen' problem. If position is changed, physics system is using new coordinates to continue its work, hence sprite's surprising behavior. Let's say,that sprite is moving and when it's clicked it should move 100px on the right and then continue its movement), maybe with a different speed. How to achieve that? My solution is: sprite.body.moves = false;object.sprite.x += 100;... and then in game's update() function: function update() { sprite.body.reset(sprite.x, sprite.y); sprite.body.velocity.x = 10; // new velocity sprite.body.moves = true;}I understand, that physics system must be after one update, otherwise switching between body.moves = falseand body.moves = truewill not have a chance to work. After that sprite is translated 100px in the right, plus it has new velocity. The question is: is there a proper Phaser way to achieve that without splitting this operation on instructions executed before and after update() function? It's seems like a common need and yet it takes that little extra effort to achieve desired effect
  6. Hi all! I'm coding a multiplayer game with server verification and the first thing you need when doing so, is a deterministic environment. And my issue is that velocity seems not to be even remotely reliable... I made a sandbox to illustrate my issue : http://phaser.io/sandbox/edit/vLcJZUDX You can see that from frame to frame, the delta x (in px/s) is really different. I could set the x and y myself (without using velocity), but then I would loose the collision detection, which I want to use, of course. Am I using velocity wrong? Is my sandbox poorly done? Thanks a lot guys!
  7. Hi, Programming on my game, i came across a very strage behavoir. For some reason my body does not react to velocity. It can be set, but it does not have any effect. MoveLeft or MoveRight on the other hand works fine. Is this a commen bug, or am i just missing something? Help would be greatly appreciated. Here is some of the code I use: var player;var ground;var map;var levelLayer;var objectsLayer;var bg;var spikes;var collision_tiles;var move_distance = 50;var jump_height = 10000;var playState = { create: function() { // cursor cursors = game.input.keyboard.createCursorKeys(); // Create Background and fix camera on background bg = game.add.sprite(0, 0, 'background'); bg.fixedToCamera = true; // Create map from tileset and JSON & add Collision & add .png's map = game.add.tilemap('test2'); map.addTilesetImage('tiles_spritesheet','tiles'); map.addTilesetImage('magicBoni','magicBoni'); map.addTilesetImage('Map','Map'); map.addTilesetImage('spike-up','spike-up'); map.addTilesetImage('black-tiles64','black-tiles64'); // Add layers to map levelLayer = map.createLayer('Kachelebene 1'); levelLayer.resizeWorld(); map.setCollisionBetween(1,3000,true,levelLayer); // Create slope map var slopeMap = {'1':1,'2':1,'3':2,'4':3,'5':4,'6':5,'7':6,'8':7,'9':8,'10':9,'11':10,'12':11,'13':12,'14':13,'15':14,'16':15,'17':16,'18':17,'19':18,'20':19,'21':20,'22':21,'23':22,'24':23,'25':24,'26':25,'27':26,'28':27,'29':28,'30':29,'31':30,'32':31,'33':32}; collision_tiles = game.physics.ninja.convertTilemap(map,levelLayer,slopeMap); // Player settings player = game.add.sprite(0, 20, 'player'); game.physics.ninja.enableCircle(player,player.width/2); game.physics.ninja.enableBody(player); game.physics.ninja.enable(player); player.body.bounce.y = 0.8; game.physics.ninja.gravity = 0.3; game.camera.follow(player); game.add.sprite(0, 0, 'foreground'); }, update: function() { for (var i = 0; i < collision_tiles.length; i++) { player.body.circle.collideCircleVsTile(collision_tiles[i].tile); } if (cursors.left.isDown) { player.body.moveLeft(move_distance); } else if (cursors.right.isDown){ player.body.moveRight(move_distance); } // DOES NOT WORK! if (cursors.up.isDown && player.body.touching.down == true) { player.body.velocity.y = jump_height; } }}
  8. I have 2 bouncing balls which are bouncing off world borders and also off each other. The balls do maintain their speed when bouncing off the world borders but they lose their speed when bouncing off each other. I'd like them to maintain their speed after they collide with each other. I realise this is quite against the physics but is this doable? Here it the game implemented with p2 physics http://finspin.github.io/bubble-game/version-2/ and the code below. And here is the same game implemented with arcade engine where balls are bouncing without losing the speed http://finspin.github.io/bubble-game/version-1/. I switched from the arcade engine to p2 after I learned arcade can't handle collision of circular objects. var game = new Phaser.Game(480, 640, Phaser.AUTO, 'Bubble Game', { preload: preload, create: create, update: update, render: render});var b1, b2, bubble1, bubble2;function preload() {}function create() { game.stage.backgroundColor = "#000"; game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setImpactEvents(true); var bubbleCollisionGroup = game.physics.p2.createCollisionGroup(); game.physics.p2.updateBoundsCollisionGroup(); b1 = game.add.graphics(); b1.beginFill(0xFF0000, 1); b1.drawCircle(0, 0, 50); bubble1 = game.add.sprite(game.world.width - 380, game.world.height - 50); bubble1.addChild(b1); bubble1.anchor.setTo(0.5, 0.5); b2 = game.add.graphics(); b2.beginFill(0xFFFFFF, 1); b2.drawCircle(0, 0, 50); bubble2 = game.add.sprite(game.world.width - 245, game.world.height - 50); bubble2.addChild(b2); bubble2.anchor.setTo(0.5, 0.5); bubbles = game.add.group(); bubbles.add(bubble1); bubbles.add(bubble2); game.physics.p2.enable(bubbles); bubbles.forEach(function (bubble) { bubble.body.setCircle(50); bubble.body.setCollisionGroup(bubbleCollisionGroup); bubble.body.collides([bubbleCollisionGroup, bubbleCollisionGroup]); }); var bubbleMaterial = game.physics.p2.createMaterial('bubbleMaterial'); var worldMaterial = game.physics.p2.createMaterial('worldMaterial'); bubble1.body.setMaterial(bubbleMaterial); bubble2.body.setMaterial(bubbleMaterial); game.physics.p2.setWorldMaterial(worldMaterial, true, true, true, true); var contactMaterial = game.physics.p2.createContactMaterial(bubbleMaterial, worldMaterial); contactMaterial.friction = 0; contactMaterial.restitution = 1.0; bubble1.body.damping = 0; bubble1.body.velocity.x = 200; bubble1.body.velocity.y = -200; bubble2.body.damping = 0; bubble2.body.velocity.x = -100; bubble2.body.velocity.y = 250;}function update() {}function render() {}
  9. How could I make ball bouncing off the world borders constantly? I tried to play around with contactMaterial properties but nothing seems to do the job. The ball will slowly lose its velocity. I'd like it to bounce constantly with constant velocity. var game = new Phaser.Game(480, 640, Phaser.AUTO, 'Bubble Game', { preload: preload, create: create, update: update, render: render});var bubble1;function preload() { game.load.image('bubble1', 'assets/bubble1.png');// game.load.image('bubble2', 'assets/bubble2.png');// game.load.image('bubble3', 'assets/bubble3.png');}function create() { game.stage.backgroundColor = "#000"; game.physics.startSystem(Phaser.Physics.P2JS); bubble1 = game.add.sprite(game.world.centerX, game.world.centerY, 'bubble1'); game.physics.p2.enable(bubble1); bubble1.body.setCircle(50); var bubbleMaterial = game.physics.p2.createMaterial('bubbleMaterial', bubble1.body); var worldMaterial = game.physics.p2.createMaterial('worldMaterial'); game.physics.p2.setWorldMaterial(worldMaterial, true, true, true, true); var contactMaterial = game.physics.p2.createContactMaterial(bubbleMaterial, worldMaterial); contactMaterial.friction = 0; contactMaterial.restitution = 1.0; contactMaterial.stiffness = 0; contactMaterial.relaxation = 0; contactMaterial.frictionStiffness = 0; contactMaterial.frictionRelaxation = 0; contactMaterial.surfaceVelocity = 0; bubble1.body.velocity.x = 200; bubble1.body.velocity.y = 200;}function update() {}function render() {}
  10. Hello guys, My player has a sprite that follows it everywhere. In order to follow it, I read I had to use body.velocity because if the x/y coordinates are used directly it will mess up the collision detection. So everything worked fine until I ran into a particular scenario. When my player jumps on top of a moving sprite and stands still, Phaser sees my player's velocity as zero. The player has zero velocity relative to the moving sprite because its on top of it, but relative to the screen it is still moving. That makes sense, but the sprite that follows the player stops following it completely since it reads the player's velocity as zero. They begin to drift apart as the player moves away on the moving sprite. Again, I would use the x/y coordinates but I cant do that since collision detection will not work. Is there a work around for this?
  11. Hi, i've a quick question. Is it possible to move a group of sprites in a smooth way. Velocity of 300, for moving from right to left. Every few seconds i've created a group of sprites from 16 - 128. But in movement i can see a jittering. Tested on Chrome and Cocconjs. I've tried a lot of different thinks. - Not velocity. X and y of the sprite directly in the update function - this.game.renderer.renderSession.roundPixels = true; - create one sprite with arcade physic and all other only as childs. - Super small image May be someone has an idea to move sprites in a smoother way. In the game jetpack joyride, there are also groups of a lot of sprites (coins)..... Regards, Chris
  12. Eraph

    Drifting Dolly

    Hi guys, I've spent far too much time looking at this problem and I can't get to the bottom of it. I have two sprites; one player sprite and one dolly sprite (which will be invisible, just a point in the world for the camera to look at). What happens on every update, is that the position of the dolly should move depending on the current vector of the player sprite. This includes angle and distance, and the angle is not always the way the player sprite is facing (I've got the mechanics of this nailed, don't worry about why I'm trying to do this). The problem I'm having is that the dolly ever-so-slightly drifts from where it should be. I've made up a greatly simplified example on Cloud9 you can take a look at the code here: https://ide.c9.io/eraph/phaser The user presses the UP key and the player sprite increases its velocity (it's in space, so no friction). After the velocity is set, the camera position is set. if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { this.newVelocity = game.physics.arcade.velocityFromAngle(this.player.angle, 10); } this.player.body.velocity.x += this.newVelocity.x; this.player.body.velocity.y += this.newVelocity.y; // Set the position of the dolly relative to the position of the player ship // Why does this drift? this.dolly.position.setTo(this.player.body.center.x + 100, this.player.body.center.y);In this example, I'm just taking the position of the player sprite and adding 100 to the X position. Should be pretty straight-forward, right? Well, run it and see what happens. The dolly edges closer to the player sprite as the velocity of the player sprite increases. I tried moving the dolly position update into the postUpdate() part but then the camera won't keep up. So what do I do to keep the dolly at a steady distance? Is this to do with the order in which positions are calculated, because of the use of Arcade physics velocity? Cheers! PS, if the virtual machine is running already you should be able to try it out here: https://phaser-eraph.c9.io/drift.html
  13. Hi, I'm trying to do an infinite runner with random islands. Island should be a tilemap generated dynamically. The character have to jump over and over island to survive. All exemples I saw with tilemap is a static map limited world. I want to use tilemap to skin it easily and access to which tile character collide (for special event). I tryed to put some velocity to tilemap/tilelayer or change to x/scrollx, like a kinectic body, but it fails. Sorry if my explanation isn't very good.. I made a draw to be more cleary : So is there a way to do something like this directly with Phaser ?
  14. G'day folks, I'm having a stab at making me a top-down space shoot 'em up. So far I've got a wee spaceship flying around with no friction by compounding angular velocities on the respective X and Y components whenever the thrust is used - grand, works a treat. What I'd like to do now is have the spaceship slowly come to a stop when the player presses the DOWN key - not deceleration as in reverse thrust, but to gradually come to a complete stop, velocity 0 in both the X and Y axes. So how I figure to do this is to call: this.game.physics.arcade.velocityFromAngle(this.currentVelocityAngle, this.brake);Again, that would be compounded onto the component X and Y properties of the ship velocity. The problem I'm having is that I can't figure out the angle of the current velocity of the ship. I can see the speed by using: this.game.debug.text('Speed: ' + this.body.speed, 32, 200);But there doesn't seem to be a similar property for the angle. I could use some good ol' trigonometry to calculate this, but I want to make sure it's not been done already!
  15. I am generally quite new to Phaser and Javascript as a whole and have some issues i need clarifying. Issue 1: Audio in my game, my Ship sound is created and started like this in the create function. shipsound = this.game.add.audio('shipsound');shipsound.play(); and should be stopped when the player collides with the finish. nextLevel: function() { shipsound.stop(); powerupCollision = false; powerdownCollision = false; this.game.state.start("MainMenu"); }, But it does not stop and carrys on through to the next state, thoughts? Issue 2: I am currently using multiple states for levels, my first level works fine, not sure if its worth mentioning but i am currently applying velocity to my player in all states in the update function. update: function () { //Player velocity player.body.velocity.x = 250; When loading into my second state where the player should start at - player = new Player(this.game, 20,50); With debug the player starts at around 1461 x position, I have no idea what is causing this issue or how to fix it. If anyone can help in any way it would be appreciated, Thank You!
  16. i have create mini game with collision system on it. the game about the ball bouncing on moveable player's box. all code is working well. the problem is while i move the box and hit the ball it become faster. i want the speed stay as it what ever happen to the ball. here is my code: game.physics.arcade.enable(box);game.physics.arcade.enable(ball); box.body.immovable = true; box.anchor.setTo(0.5, 0.5); ball.anchor.setTo(0.5, 0.5); ball.body.collideWorldBounds = true; ball.body.bounce.setTo(1, 1);ball.body.velocity.setTo(150, -150); this http://phaser.io/examples/v2/arcade-physics/bounce-knock as reference, try to push the ball using the alien, it is what i mean by the speed is changing.
  17. So I'm moving sprites across the screen with moveToXY and continually checking the velocity (in the updates function) to see if the sprite makes it to its destination, like so: if ((player.body.speed > 0) && (reachedDestination(player,destination))) { player.body.velocity.x = 0; player.body.velocity.y = 0; } This works fine, until I add the player to a group, and try to call this function on each member of the group: units.addChild(player); units.foreach(function(unit) { if ((unit.body.speed > 0) && (reachedDestination(unit,destination))) { unit.body.velocity.x = 0; unit.body.velocity.y = 0; } }); For some reason, unit.body.speed always shows up undefined. unit.body.velocity.x or y doesn't work either. I'm baffled as to why the function works on a single object but not on multiple.
  18. there are several occations where my player gets faster and faster all the time without limit.. (this is on purpose but it shouldn't end up in lightspeed.. a velocity of 800-1000 would be more than enough) how would i define such a limit and make sure it's applied? thx in advance
  19. So I decided to use Arcade physics for my game and it seemed like it had some really awesome features. One of the problems I encountered though was that for the arcade system to be fully functinoal, it seemed like I had to use velocity to make movements, rather than just assigning the X and Y. This wans't a problem and I quickly adjusted. Now the problem came today, when another player was supposed to test the game. Her computer didn't handle it as well and that's when I realized that velocity is based on how much time each update takes. This is a huge problem because this meant that on a lower-end machine the player would sometimes drop through the floor! This game is supposed to be used at an event, so that's REALLY unfortunate. Is there ANY way I can change this? So velocity always assumes a certain amount of time passed between each frame?
  20. So my game, ( http://narric.com/underdog_football/ ), has this problem where i go through the tile map when I fall from high spots or if i jump up with high velocity. I have the gravity really high, when i lower it there is no problem, BUT I WANT THE GRAVITY HIGH! I don't think its a problem with the tile map because there is no problem when i lower the gravity and jump velocity. The code below isnt all the code for the game. (I normally have "preload" in another .js file and i got rid of the code for the intro screen and there is a boot file thats not included). I'm new to phaser and coding in general so any help is appreciated. var game = new Phaser.Game(1152,672, Phaser.AUTO, 'game_div');preload: function() { this.load.image('box', 'images/box.png'); // loading the tileset image this.load.tilemap('boxy', 'images/boxy.json', null, Phaser.Tilemap.TILED_JSON); this.load.spritesheet('player', 'images/football_sprite20.png',72,132,20); },create: function() { this.physics.startSystem(Phaser.Physics.ARCADE); map = this.add.tilemap('boxy'); // Preloaded tilemap map.addTilesetImage('box'); // Preloaded tileset layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); map.setCollisionBetween(0, 1); this.player = this.add.sprite(100, 100, 'player'); this.player.anchor.setTo(.5, 1); this.player.animations.add('walking', [0,1,2,3,4,5,6,7], 18, true); this.player.animations.add('sprinting', [12,13,14,15,16,17,18,19], 25, true); this.player.animations.add('jumping', [11], false); this.player.animations.add('idle', [8,9,10,9], 4, true); this.physics.arcade.enableBody(this.player); this.player.body.collideWorldBounds = true; this.player.body.bounce.y = 0.05; this.player.body.gravity.y = 5000; this.player.scale.x = 1; this.player.scale.y = 1; cursors = this.input.keyboard.createCursorKeys(); jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);},update: function() { this.physics.arcade.collide(this.player, layer); this.player.body.velocity.x = 0; //====JUMPING==== jumpButton.onDown.add(jumpAction, this); function jumpAction(){ if (this.player.body.onFloor()) { this.player.body.velocity.y = -1400; this.player.body.gravity.y = 5000; this.player.animations.play('jumping'); if (cursors.down.isDown || sKey.isDown) { this.player.body.velocity.y = -1800; this.player.body.gravity.y = 5500; } } } //====MOVING LEFT==== if (cursors.left.isDown) { this.player.body.velocity.x = -500; this.player.scale.x = -1; this.player.scale.y = 1; if (cursors.down.isDown && this.player.body.onFloor()) { this.player.body.velocity.x = -730; this.player.animations.play('sprinting'); } else if(this.player.body.onFloor()){ this.player.animations.play('walking'); } } //====MOVING RIGHT==== else if (cursors.right.isDown) { this.player.body.velocity.x = 500; this.player.scale.x = 1; this.player.scale.y = 1; if (cursors.down.isDown && this.player.body.onFloor()) { this.player.body.velocity.x = 730; this.player.animations.play('sprinting'); } else if(this.player.body.onFloor()){ this.player.animations.play('walking'); } } //====STANDING IDLE==== else if(this.player.body.onFloor()){ this.player.animations.play('idle'); } }};
  21. Good Morning, I'm trying to have my 'player' sprite be able to move 'box' sprites around the screen. So far, I can push the box... but it doesn't stop moving. The effect is like the box is on ice. I touch it and it slides away. Here's my code: function update() { game.physics.arcade.collide(player, block, moveBlock, null, this);}function moveBlock() { if (block.body.touching.up) { block.body.velocity.y = 75; } else if (block.body.touching.down) { block.body.velocity.y = -75; } else { block.body.velocity.y = 0; } if (block.body.touching.left) { block.body.velocity.x = 75; } else if (block.body.touching.right) { block.body.velocity.x = -75; } else { block.body.velocity.x = 0; }}The problem seems to be that the 'else' of the statements is never "true". Now, I put a console.log statement in the 'else' portion for vertical movement, and noticed that the only time it ever responded was when I went from pushing the block vertically to horizontally. So how I do I get the dang thing to stop moving when my player sprite is not touching it? Thanks for your help!
  22. Hi, I'm newbie in Phaser (excuse my english)... Currently I'm developing pinball game. I have created flippers (paddle) via revolute constraints and ball in P2 physics... Everything works perfect but I need to make flippers more powerfull when they hit to ball (I need ball acceleration)... currently CreatePaddle = function(game,x,y, side) { Phaser.Group.call(this, game); this.side = side; this.flipped = false; this.sprite_two = game.add.sprite(x, y, 'paddle'); game.physics.p2.enable(this.sprite_two, true); //this.sprite_two.body.clearShapes(); if(side == 'right') { this.sprite_two.body.loadPolygon('physicsData', 'paddle2'); this.maxAngle = 30; this.pivotOffsetX = 50; this.sprite_two.scale.x *= -1; this.pivotPoint = this.game.add.sprite(this.sprite_two.position.x + this.pivotOffsetX, this.sprite_two.position.y); this.pivotOffsetX = 50; } else { this.sprite_two.body.loadPolygon('physicsData', 'paddle'); this.maxAngle = -30; this.pivotOffsetX = -50; this.pivotPoint = this.game.add.sprite(this.sprite_two.position.x + this.pivotOffsetX, this.sprite_two.position.y); } this.game.physics.p2.enable(this.pivotPoint); this.pivotPoint.body.static = true; this.pivotPoint.body.clearCollision(true,true); this.flipperConstraint = this.game.physics.p2.createRevoluteConstraint(this.sprite_two, [this.pivotOffsetX, 0], this.pivotPoint, [0, 5]); this.flipperConstraint.upperLimitEnabled = true; this.flipperConstraint.lowerLimitEnabled = true; return this.flipperConstraint;}Ball is created like this: //ball - circlecircle = game.add.sprite(470, 300, 'circle');circle.anchor.setTo(0.5, 0.5);game.physics.p2.enable(circle, false);circle.body.setCircle(16);circle.body.fixedRotation = true;Flippers are loaded like this: this.paddle1 = new CreatePaddle(game, 270, 2390, 'left');this.paddle2 = new CreatePaddle(game, 460, 2390, 'right');But how can I add more power to ball which collide with my flipper (paddle) ? Should I create custom material for flipper or is there easier way? Thanks for answers.
  23. Ok i'm kind of stuck here ... I have a a sprite that I move using the following: target.sprite.body.velocity.x += target.power/2;target.sprite.body.velocity.y -= target.sprite.body.velocity.x*1.5;I would like to know the coordinates of where the sprite will stop instantly, without having to wait for the animation of the sprite to finish. Anyone knows how I could achieve that? Thanks!
  24. 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!
  25. Hey guys jg here, So I recently stumbled across PhaserJS and found some cool youtube tutorial videos and documentation online. I've managed to display my sprite on the canvas. I wanted to get it to drop down so I set the sprites velocity.y = 100; But it's not moving. Can someone tell me what's wrong with my code? var star;var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload(){ game.load.image('star','star.jpg'); } function create(){ star = game.add.sprite(game.world.centerX,0,'star'); star.velocity.y = 100; } function update(){ }