0 Favourites

# Rotate sprite while jumping

• 6 posts
• Working on a Platform game, I have the Player Sprite.

What I want to do, is rotate it while it jumps, then bring it back to 0 when it reaches the ground.

I almost got it to work, but the problem is that when it reaches the ground it "shakes" a bit until it settles down. Any idea what I'm doing wrong?

Thanks!

http://i.imgur.com/Tlifu.jpg

<img src="http://i.imgur.com/Tlifu.jpg" border="0">

• Don't use the same sprite for rotation and platforming. Because of collision issue, when your sprite is rotated 15 degree one corner will touch the ground.

Then you set it to 0 degree it goes back in fall mode. Probably creating some wiggling.

You should then do something like setting another sprite to follow your platform sprite. I usually set the platform behavior on my collision box only and then set the eye candy graphics of the character on another sprite that doesn't handle collision.

Let's call it "PlayerSkin"

(You'll have to put your mirroring logic to the PlayerSkin instead by the way)

``````Global number JRotSpeed = 120  // in degree per second
Global number JAngleLimit = 15  //Limit of jump rotation angle

Player: On Jump
-> PlayerSkin: set rotSpeed to PlayerSkin.isMirrored ? JRotSpeed : -JRotSpeed

Player: On Fall
-> PlayerSkin: set rotSpeed to PlayerSkin.isMirrored ? -JRotSpeed : JRotSpeed

Player: On Landed
-> PlayerSkin: set rotSpeed to 0
-> Player: set angle to 0

Every Ticks:
-> PlayerSkin: Set Angle to Clamp(Player.angle+rotSpeed*dt,-JAngle,JAngle)``````

(Sorry, didn't keep your awesomely long variable names :D)

Use dt, this way your movement isn't fps dependant

if you rotate 2 degree per frame the movement won't have the same speed at 30 and 60fps

By multiplying by dt (time delta = time (in seconds) between the previous and the current frame) you'll always keep the same speed.

And also it allows you to express your values per seconds (adding 1*dt to a value each frame, this value will go up to 1 per second)

Anyway it should work

• Thanks for the info!

I have to admit I didn't FULLY grasp the concept of the dt, but I'm going with you here. This is what I have now, however it's still not working properly! Now when I jump it jitters :)

If I remove the Clamp then it doesn't jitter, but it goes above the 15 degrees (obviously).

Also note (don't know if it was clear from my previous screenshot)- when the play falls down I want it to be in he opposite of that degrees. I mean that if when jumping I make it go to -15, then when it falls it should be 15, and then settle on 0 when it hits the ground.

So here's the updated Events Sheet, thanks for the help!

http://i.imgur.com/x2o08.jpg

<img src="http://i.imgur.com/x2o08.jpg" border="0">

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I did using frames, because after many tries, my version was not good enough. But using frame animations, it's perfect.

Also, I was having several issues with the detection, also when pinning the animation to a invisible player.

The sandBOX was made with these rotating frames, you can check them, and you'll see what I mean of feeling good, because the animation always will show the right frame on the right moment of the rotation, instead of depending from forces, torques, etc.

• Ok how I ended up doing this (and now it works great) is this:

• define a new RotateTo instance variable
``````PlayerBox on Platform Jump
Player.IsMirrored? PLAYER_JUMPING_ANGLE : -PLAYER_JUMPING_ANGLE

PlayerBox on Platform Fall
Player.IsMirrored? -PLAYER_JUMPING_ANGLE : PLAYER_JUMPING_ANGLE

PlayerBox on Platform Landed
Set Player.RotateTo = 0
Set Player.Angle = 0

System.Tick
Rotate Player PLAYER_JUMP_ROTATE_SPEED*dt toward Player.RotateTo
``````

Thanks for the help!

• Oh right, I think the jittering is caused by the fact that when you set angles to a negative value, c2 converts it to a 0-360 range.

so, as soon as you rotate counter clockwise past 0 degree it will go to 360 then it's clamped to 15...

So basically you have a sequence of values like that (if isMirrored is true and you have a steady 60fps which gives you a 1/60=0.017 for the value of dt) :

frame 1: 0

frame 2: clamp(0-120*0.017,-15,15) = -2.04

-> converted to 357.96

frame 3: clamp(357.96 - 2.04,-15,15) = 15

... ... ...

and it will go back to 0 as long as you're jumping

So yeah using your RotateTo variable is a good idea (:

And for the dt... Basically to understand how things work, look at how the values evolve when using it.

dt is the time between the previous and the current frame.

in a 60fps game,

<font face="Courier New, Courier, mono">dt = 1/fps = 1/60 = 0.01666666666</font>

(dt is the "second per frame" so spf = 1/fps :D )

let's simplify to 0.017

If you add dt to a value every frame:

<font face="Courier New, Courier, mono">0.017+0.017+0.017+..... </font>

After exactly one second, which is 60 frames, the value will be equal to

<font face="Courier New, Courier, mono">60*1/60 = 1</font>

in a 30 fps game, after one second, which is 30 frames, you'll get

<font face="Courier New, Courier, mono">30*1/30 = 1</font>

So basically, in whatever fps you are, the succession of addition will all reach 1 after one second.

if you add 5*dt, the value will reach 5 after one second

so basically, if you

<font face="Courier New, Courier, mono">set X to self.X + 5*dt </font>

you add 5px to X every one second, so you move your object at exactly 5px per second

It works the same with angle:

<font face="Courier New, Courier, mono">set angle to self.angle + 5*dt </font>

will rotate at 5 degree per second.

that's the holy magic of dt in a nutshell =)

• 6 posts