the spaceship in my program should be moving in the direction which the front of it is pointing to. So it should move when i press "W" into the angular direction in which the spaceship is pointing. You can move in the opposite direction with "S", and with "A" and "D" the spaceship will rotate.
Now, as long as you dont rotate anything it will move up and down just as it should do it. And if you rotate the spaceship, it will get displayed in the correct angle, but when you try to move in the direction it is pointing, ehr, yeah it is doing what it wants to do, and not what it sould do.
Just have a look at the love file and you will see the problem.
(Ignore the improvised tilemap in the background, it is only optical and was a test)
Here's the part of code which I think the problem is in:
Code: Select all
--Generate Speed
checkW = love.keyboard.isDown(cConfig[0],cConfig[1])
checkS = love.keyboard.isDown(cConfig[2],cConfig[3])
checkA = love.keyboard.isDown(cConfig[4],cConfig[5])
checkD = love.keyboard.isDown(cConfig[6],cConfig[7])
if checkA == true then
units[unitselect].body:applyTorque(-units[unitselect].rotspeed)
end
if checkD == true then
units[unitselect].body:applyTorque(units[unitselect].rotspeed)
end
local forceX = ((100/360)*math.deg(units[unitselect].body:getAngle()))*units[unitselect].accleration
local forceY = units[unitselect].accleration-forceX
if checkW == true then
local angle = math.deg(units[unitselect].body:getAngle())
if angle < 90 then
units[unitselect].body:applyForce(forceX, -forceY)
elseif angle < 180 then
units[unitselect].body:applyForce(forceX, forceY)
elseif angle < 270 then
units[unitselect].body:applyForce(-forceX, forceY)
elseif angle < 360 then
units[unitselect].body:applyForce(-forceX, -forceY)
end
end
if checkS == true then
angle = math.deg(units[unitselect].body:getAngle())
if angle < 90 then
units[unitselect].body:applyForce(-forceX, forceY)
elseif angle < 180 then
units[unitselect].body:applyForce(-forceX, -forceY)
elseif angle < 270 then
units[unitselect].body:applyForce(forceX, -forceY)
elseif angle < 360 then
units[unitselect].body:applyForce(forceX, forceY)
end
end
level[roomselect].world:update(dt)