Sign in to follow this  
angelkom

How make player rotate in jump function?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.