Hey so i have a sprite class, and i am making it turn 360 degrees a second, while increasing speed at the same time. However I end up spiraling and not staying on the original circle formed by the continuous turning of 360 degrees per second.
How can i fix this? The开发者_如何学Go sprite needs to go faster and stay on the same path.
here's the code:
box.Accelerate(10*Window.GetFrameTime());
box.Turn(360.0*Window.GetFrameTime());
If you want to make a sprite go in a circle, put that in the code. For example,
float time = Window.GetFrameTime();
angle += speed * (time - lastTime);
lastTime = time;
float x = sinf(angle), y = cosf(angle);
box.SetPos(50*x + center.x, 50*y + center.y);
box.Turn(angle + QUARTER_TURN);
If your sprite is accelerating (moving faster every second) but still turning at a constant speed of 360 degrees per second, it will always move in an outward spiral.
Think of it this way:
If your sprite is moving around a circle of radius 1 (i.e. a unit circle), turning at a speed of 360 degrees per second and moving at a speed of 2*pi units (i.e. the circumference of your circle) per second, the sprite will be moving all the way around the circle every one second.
If you increase the speed at which the sprite moves, but it stays on the same circle, it will make it around the circle faster than once every one second. If it is still going to make it around the circle once per second, the circle must get bigger.
To keep your sprite on the same circle, it must also increase the rate at which it turns proportionally to the rate at which it accelerates.
精彩评论