Hi this maybe more of a programming question, but I can't write any code before I get my head around how its going to work so maybe you guys can help me out.
A sprite in my game can move along the x axis, to do this I'm giving it a velocity value. Now I need this sprite to rotate depending on what this velocity value is. Obviously 0 velocity means it faces forward, a low negative number of velocity means it is turning left, smaller the negative number, the more I want to rotate the sprite. This is the same for positive values too, any positive value means its rotating right higher the value the more it should rotate.
Is there a formula to help me work this out?
I've tried this in code so far, and it works to a certain extent, just when the velocity slows back down the sprite doesn't rotate back to the centre, it stays in the position its been rotated to. The only time it faces forward is when its smack in the centre of the screen.
Hope I've posted in the right forum and section, and you can help me!
float Proportion = 0.25f; // adjust value to needs
float maxDiff = 1; // adjust to limit the maximum change of the orientation.
player.rotation += fmaxf(fminf(playerVelocity.x * Proportion, maxDiff), -maxDiff);