nak3ddogs Posted July 28, 2014 Share Posted July 28, 2014 helo.Can i change the body size in the update function? i want my player to crouch to avoid some stuff.so when i try change the player's body size in the update section the player had launched like a rocket.player1 = this.add.sprite( 100, 0, 'character'); this.physics.enable(player1, Phaser.Physics.ARCADE); player1.body.bounce.y = 0.3; player1.body.gravity.y = 1000; player1.body.maxVelocity.y = 600; player1.body.collideWorldBounds = true; player1.anchor.x = 0.5; player1.anchor.y = 1; player1.body.setSize(24, 70, 0, 0 ); player1.body.immovable = true;update: function(){ this.physics.arcade.collide(player1, layer1); //player1 controll if (player1.body.touching.down || player1.body.onFloor()) { if (this.cursors.down.isDown) { player1.body.setSize(24, 70, 0, 0); if (Math.abs( player1.body.velocity.x) > 240 && this) { player1.animations.play('roll') } else if (player1.animations.currentAnim.name != 'crouch') { player1.animations.play('crouch'); }; // console.log(player1.animations.currentAnim.name) } else if (this.cursors.left.isDown) { player1.body.velocity.x = -250; player1.scale.x = -1; player1.animations.play('run'); } else if (this.cursors.right.isDown) { player1.body.velocity.x = +250; player1.animations.play('run'); player1.scale.x = 1; } else { player1.body.velocity.x = 0; player1.animations.play('stop'); } if (this.cursors.up.isDown) { player1.body.velocity.y = -400; player1.animations.play('jump'); }; }; }, Link to comment Share on other sites More sharing options...
lewster32 Posted July 28, 2014 Share Posted July 28, 2014 This is the integration at work, changing the size changes the positioning of the sprite, which is interpreted by the physics system as a sudden change in velocity. You may be able to call player1.body.reset(player1.x, player1.y) straight after changing the size maybe? Depending on your anchor or offset you may need to change the player.y a bit to move the player down as well as making it smaller. nak3ddogs and psyconiak 2 Link to comment Share on other sites More sharing options...
nak3ddogs Posted July 28, 2014 Author Share Posted July 28, 2014 i set the player.body.anchor to the bottom of the sprite. but i think when i change the size of the body's velocity is originated from the body top left corner's position changes. is it possible?so when i changed the body size the difference of the previous and the new position of the top left corner is 30 px. and it is happen in a 1/60 s. 30*60 = 1800. is the new velocity.y 1800? Link to comment Share on other sites More sharing options...
nak3ddogs Posted July 28, 2014 Author Share Posted July 28, 2014 thx. the body.reset have worked lewster32 1 Link to comment Share on other sites More sharing options...
psyconiak Posted August 17, 2015 Share Posted August 17, 2015 i searched ages for this solution. all the other examples beeing solved regarding this issue, were without a changed anchor. setSize doesnt work if you set an anchor (obviously). ty so much <3 Link to comment Share on other sites More sharing options...
Recommended Posts