help with movement
Posted: Fri Mar 17, 2017 3:06 am
So I was working on a bit of code for player movement and I wanted to add the option to be able to hold shift to sprint
This results in the player always moving at sprint speeds.
I have also tried something like this and it doesn't seem to work either. I think I might be doing something wrong. Over all im out of ways I know to fix it or at least ones that I have thought of.
Code: Select all
function love.update()
if love.keyboard.isDown("w") then
py = py - 1
end
if love.keyboard.isDown("s") then
py = py + 1
end
if love.keyboard.isDown("a") then
px = px - 1
end
if love.keyboard.isDown("d") then
px = px + 1
end
if love.keyboard.isDown("lshift" and "w") then
py = py - 10
elseif love.keyboard.isDown("lshift" and "s") then
py = py + 10
end
if love.keyboard.isDown("lshift" and "a") then
px = px - 10
elseif love.keyboard.isDown("lshift" and "d") then
px = px + 10
end
Code: Select all
ws = false
ss = false
as = false
ds = false
function love.update()
while(ws == true) do
py = py - 10
end
while(ss == true) do
py = py + 10
end
while(as == true) do
px = px - 10
end
while(ds == true) do
px = px + 10
end
end
function love.keypressed(key)
if key == "right" then
if key == down then
px = px + 3
end
end
if key == "lshift" and key == "s" then
ss = true
end
if key == "lshift" and key == "a" then
as = true
end
if key == "lshift" and key == "d" then
ds = true
end
end
function love.keyreleased(key)
if key == "lshift" and "w" then
ws = false
end
if key == "lshift" and "s" then
ss = false
end
if key == "lshift" and "a" then
as = false
end
if key == "lshift" and "d" then
ds = false
end
end