Hi.I use SFML with Box2D.I can't rotate the character sprite like GTA 2.My codes:
Update:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
body->ApplyLinearImpulse(b2Vec2(0,-10 * UNRATIO),body->GetWorldCenter(),true);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
body->ApplyLinearImpulse(b2Vec2(0,10* UNRATIO),body->GetWorldCenter(),true);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
body->ApplyLinearImpulse(b2Vec2(-5* UNRATIO,0),body->GetWorldCenter(),true);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
body->ApplyLinearImpulse(b2Vec2(5* UNRATIO,0),body->GetWorldCenter(),true);
Render:
b2Transform trans = body->GetTransform();
animatedSprite.setOrigin(width / 2, height / 2);
angle = trans.q.GetAngle();
animatedSprite.setRotation(RADTODEG(angle) );
animatedSprite.setPosition(body->GetWorldCenter().x * RATIO,body->GetWorldCenter().y * RATIO);
sf::Time frameTime = frameClock.restart();
animatedSprite.play(*currentAnimation);
// update AnimatedSprite
animatedSprite.update(frameTime);
window.draw(animatedSprite);
I drew the problem.Can you help me?Thanks.