Log In  

What am I doing wrong here? It's driving me crazy!

I've made an onGround function that check if there's a flagged sprite below you, which seems to be working, but when you run it, the gravity (which should kick in when not on the ground) never gets applied.

I've used the print function to debug whether onGround is working correctly and it is, so why is the

if not onground then
  dy+=grv
end

part not working?

x=60
y=112
dy=0
jmp=5
grv=0.5

function _update()
    jumping()

    y+=dy
end

function _draw()
 cls()
 map(0,0,0,0,16,16)
 spr(1,x,y)

 print(solid(x,y+9),1,1,7)
end

function jumping()
    -- jumping
    if onground and
    btnp(4) then
        dy=-jmp
    end
    -- gravity
    if not onground then
        dy+=grv
    end
    -- problem area above!!!!--
end

function solid(sx,sy)
 local tilex=flr(sx/8)
 local tiley=flr(sy/8)

 if fget(mget(tilex,tiley),0) then
    return true
 else
    return false
 end
end

function onground()
    if solid(x,y+9) or
    solid(x+8,y+9) then
        return true
    else
        return false
    end
end
P#44158 2017-09-13 17:20 ( Edited 2017-09-13 21:29)

from what you posted it looks like you are not actually ever calling the "onground" function; instead you are essentially checking for the existence of the function, so it always evaluates to true.

change "if onground" to "if onground()", etc.

P#44159 2017-09-13 17:23 ( Edited 2017-09-13 21:27)

You delightful angel!

Seems so obvious now :)

P#44160 2017-09-13 17:29 ( Edited 2017-09-13 21:29)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 00:37:34 | 0.005s | Q:10