angelkom Posted February 28, 2014 Share Posted February 28, 2014 How can I make the player rotate in jump function i'm using flying dog demo, the player doesn't jump if I put in jump function, but if I put in update function it rotates but I want to rotate only when he jumps I tried with this.sprite.rotation = -1, this.sprite.rotate, this.body.rotation, this.body.rotate, this.sprite.angle, this.body.angle but no luck Quote Link to comment Share on other sites More sharing options...
enpu Posted February 28, 2014 Share Posted February 28, 2014 This should do it: this.sprite.rotation = 0.4; Quote Link to comment Share on other sites More sharing options...
angelkom Posted February 28, 2014 Author Share Posted February 28, 2014 jump: function() { this.sprite.rotation = -0.4; if(this.body.position.y < 0) return; this.body.velocity.y = this.jumpPower; game.sound.playSound('jump'); } it doesn't work Quote Link to comment Share on other sites More sharing options...
thiezar Posted March 1, 2014 Share Posted March 1, 2014 Well of course id doesn't work because you have to check wether the player is jumping or not with a boolean variable.But I do this in another way:In the update function of the player I check if it's body's y velocity is <0 (going up) or >0 (going down) and then I adjust it's sprite rotation. if(this.body.velocity.y < 0){ this.sprite.rotation = -0.4;}else{ this.sprite.rotation = 0;}Since the rotation is immediate I would suggest to lerp the rotation. Quote Link to comment Share on other sites More sharing options...
angelkom Posted March 1, 2014 Author Share Posted March 1, 2014 Yes I fix that I remembered about the velocity thing thanks anyway Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.