Julia Posted November 17, 2014 Share Posted November 17, 2014 Hey, I was wondering how I could get a few platforms to move from left to right and back, using platforms from my platformgroup.The problem is the platform isn't bouncing back from the sides and changing the velocity to + or -. Currently I have this (for only one platform): platforms.getAt(3).body.velocity.x = -100;platforms.getAt(3).body.bounce.set(1);Any suggestions? Link to comment Share on other sites More sharing options...
markusT Posted November 17, 2014 Share Posted November 17, 2014 Check this example, hope that helps http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=bounce.js&t=bounce Link to comment Share on other sites More sharing options...
Julia Posted November 18, 2014 Author Share Posted November 18, 2014 Thanks for you answer Unfortunately it's still not working... I think maybe because I'm referring to a child of a group? Or shouldn't this be a problem? Link to comment Share on other sites More sharing options...
Sam Posted November 18, 2014 Share Posted November 18, 2014 So which Physics do you enable?in the update function you could probably write: (Do not know if this is any good for performance) if ( platforms.getAt(3).x <= 0 ){ platforms.getAt(3).x += 0.1}else if ( platforms.getAt(3).x >= game.width ){ platforms.getAt(3).x -= 0.1}else{ platforms.getAt(3).x += 0.1}So this is a very sloppy solution till it is written into the update with many if statements and you have to set the "walk" way per code.So with ARCADE physics enabled you could do as posted above using bounce (theory).So you have enabled a physics on this Object ? And of course you need a Collide - in the update function game.physics.arcade.collide(this.yourPlatform, this.levelCollideOBJECTS); Link to comment Share on other sites More sharing options...
Julia Posted November 18, 2014 Author Share Posted November 18, 2014 Thank you for your answer Sam. Still not working unfortunately I have physics enabled, this is the piece of code I have in my create function :platforms = game.add.group();platforms.enableBody = true;platforms.physicsBodyType = Phaser.Physics.ARCADE;var platform = game.add.sprite(x, y, 'platform');game.physics.enable(platform, Phaser.Physics.ARCADE);platform.body.immovable = true;platform.body.allowGravity = false;platform.body.collideWorldBounds = true;platforms.add(platform);It's moving from left to right, but when it collides with the world bounds, it just stops... Link to comment Share on other sites More sharing options...
markusT Posted November 18, 2014 Share Posted November 18, 2014 Seems it missing these lines, the bounce property should work anyway. // This gets it movingplatform.body.velocity.setTo(200,200);// This makes the game world bounce-ableplatform.body.collideWorldBounds = true;// This sets the image bounce energy for the horizontal // and vertical vectors. "1" is 100% energy returnplatform.body.bounce.set(1); Link to comment Share on other sites More sharing options...
Julia Posted November 18, 2014 Author Share Posted November 18, 2014 markusT, your solution is working, but the problem seems it won't work on only one platform from my group, why I've used platforms.getAt(3). Eventually about 5 out of 20 platforms or so should be moving. So I can get this to work on all platforms but that's not what I meant Link to comment Share on other sites More sharing options...
markusT Posted November 18, 2014 Share Posted November 18, 2014 So you may need two different types of platforms. Some bounce/move and some don't. They can share the same group but have to be different sprites/platforms. Link to comment Share on other sites More sharing options...
Julia Posted November 18, 2014 Author Share Posted November 18, 2014 Okay, going to try that. Thanks for your help! I'll mark your answer as correct, because it did work Link to comment Share on other sites More sharing options...
Recommended Posts