I would like some help with moving an entity in proportion to it's rotation, For example if it is rotated 30 degrees clockwise, I would like it to move in that line from 30 degrees. I know this seems a fairly basic task/problem, but I don't quite know how to do it exactly. I have read a bit on radians and similar, but my code below doesn't seem to work correctly. This is the closest I have got to it working, but I want it to move in the same linear direction, and when you rotate it, it works correctly.
//convert the angle of the object to radians
radians = 3.1415926536 / 360*object.getRotation();
//x and y
x = 0.5f*cos(radians);
y = 0.5f*-sin(radians);
//rotate accordingly
object.move(x, y);
//convert the angle of the object to radians
radians = 3.1415926536 / 360*object.getRotation();
This isn't the right formula for converting degrees to radians (assuming object.getRotation() is returning degrees). It either needs to be ((2 * pi / 360) * degrees) or ((pi/180) * degrees)
It's hard to describe. In best words, it's point that it rotates around doesn't seem to be consistent. For example, when rotated 30 degrees, it moves in that direction as it should, but then when you change the rotation of the object to, say 60 degrees, it goes in a random direction that is not proportional to it's original direction.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
object.rotate(0.5);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
object.rotate(-0.5);
}
X = speed*sin(object.getRotation());
Y = speed*cos(object.getRotation());
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
object.move(X, Y);
}