Improved euler for movement not working

I have attempted to implement improved euler for movement of my character in a 2d platform game. When i press right the character moves right an but then slows down until a point when it starts moving left, if i press left then it just moves left.

//my euler calculations function called from main i set drag as - 0.008 and velocity as 2


void Movement::calculate()//!< calculate left and right
{//dont forget gravity +(euler equation to work out a (-10+0.04*v(t))

sf::Vector2f prevAcc = acc;//!< temp acceleration holder
sf::Vector2f prevVel = vel;//!< temp velocity holder
sf::Vector2f prevPos = pos;//!< temp Position holder
sf::Vector2f prevEulerVel = eulervel;//!< temp euler velocity holder
float average = 2;

acc=sf::Vector2f(/*gra+*/dra*eulervel);//!< calculating euler for acceleration
eulervel=sf::Vector2f(prevEulerVel+acc);//!< calculating euler for the velocity

vel=sf::Vector2f(prevVel+((acc+prevAcc)/average));//!< calculating improved euler for velocity
pos=sf::Vector2f(prevPos+((vel+prevVel)/average));//!< calculating improved euler for position
}


Topic archived. No new replies allowed.