Project link
Hi, in my game, once the bird has jumped, it faces a 22.5 angle, then falls down facing the floor, using this code:
// Map range -0.75 to -2 to 22.5 to -90
var zrot = pc.math.clamp(this.velocity, -2, -0.75);
zrot += 1;
this.entity.setLocalEulerAngles(0, 0, zrot * 90);
Now, this code works fine, but the issue is, I want to make the bird rotate back up to the 22.5 degrees.
Kinda like this
However, I cannot figure out how to do this. I know the code that makes it snap back up is this, but I am unsure on whether to change the above code or the below one.
if (this.state === 'play') {
app.fire('game:audio', 'Flap');
this.entity.sprite.speed = 2;
this.velocity = this.flapVelocity;
}
Any help towards this would be greatly appreciated, thank you 
You could change it so that there’s a desired angle to rotate towards and on every update, only move a maximum of X degrees.
1 Like
Hey @yaustar! Thanks for the quick reply.
What you mentioned is what I am struggling to do. I have set up this code:
// Map range -0.75 to -2 to 22.5 to -90
var zrot = pc.math.clamp(this.velocity, -2, -0.75);
zrot += 1;
this.entity.setLocalEulerAngles(0, 0, zrot * 90);
var pos2;
pos2 = this.entity.getEulerAngles().z;
if (pos2 < 22.5) {
//unsure of what to do here
}
So I have made it so it gets the current EulerAngle, and checks to see if it is less than 22.5 degrees.
If it is less than 22.5 degrees - well, that’s what I’m stuck on.
I’ve forked the project to demo this and ported Unity’s moveTowards function over 
https://playcanvas.com/editor/scene/925910
1 Like
Hi @yaustar
After you die once and play again, doing this first flap rotates the bird for no reason. How can I fix this? Once again, thanks so much!
Probably will need to reset this.currentZrot
to 0.25 when a new game starts.
1 Like