I'm working on a game, and i'm trying to implement the basic mechanics. I implemented gravity, smooth movement using velocity, and changing the direction of gravity (which is the main feature of the game) and now i want to do the following:
When changing the direction of the gravity, i want the player to rotate to the given angle (the gravity direction can be the 4 directions: up down left right)
so i managed to instantly "flip" the player to the given angle, but i want "smooth" transition in a given time, eg. i want the player to "stabilize" according to the gravity direction in 1 second, but i am not too familiar with radians.
the gravity changing variable is world.gravitydir, if it equals to 1, then the gravity is normal, if it equals to 3 then the gravity is "upwards"
there are also "dev controls" for the gravity changing (keyboard up, down left right)
Here is my "attempt" of the smooth rotation from upside to down (yeah its not working.. )
Code: Select all
function rotatePlayer(dt)
deg1 = player.rot
step = 0
deg2 = math.rad(0)
step = (math.deg(deg1) - math.deg(deg2))*dt
for i = deg1, deg2 do
player.rot = player.rot - math.rad(step)
end
end
http://www.mediafire.com/download/3xto9 ... title.love