Log In  

the thing is, this error only happens when I attempt to make a climbable wall.
here's my setup:

my collisions page:

--collisions

function collide_map(obj,aim,flag)
--obj = table needs x,y,w,h
--aim = left,right,up,down

local x=obj.x
local y=obj.y
local w=obj.w
local h=obj.h

local x1=0 local y1=0
local x2=0 local y2=0

if aim=="left" then
x1=x-2 y1=y
x2=x-1 y2=y+h-1

elseif aim=="right" then
x1=x+w+2 y1=y
x2=x+w+1 y2=y+h-1

elseif aim=="up" then
x1=x+3 y1=y-1
x2=x+w-3 y2=y

elseif aim=="down" then
x1=x+2 y1=y+h
x2=x+w-3 y2=y+h
end

--player hitbox test
x1r=x1 y1r=y1
x2r=x2 y2r=y2

--pixels to tiles
x1/=8 y1/=8
x2/=8 y2/=8

if fget(mget(x1,y1), flag)
or fget(mget(x1,y2), flag)
or fget(mget(x2,y1), flag)
or fget(mget(x2,y2), flag) then
return true
else
return false
end

end

my player page:
--player
function player_update()
--physics
player.dy+=gravity
player.dx*=friction

--controls
if btn(⬅️) then
player.dx-=player.acc
player.running=true
player.flp=true
end
if btn(➡️) then
player.dx+=player.acc
player.running=true
player.flp=false
end

--slide
if player.running
and not btn(⬅️)
and not btn(➡️)
and not player.falling
and not player.jumping then
player.running=false
player.sliding=true
end

--jump
if btnp(❎)
and player.landed then
player.dy-=player.boost
player.landed=false
end

--check collision up and down
if player.dy>0 then
player.falling=true
player.landed=false
player.jumping=false

player.dy=limit_speed(player.dy,player.max_dy)

if collide_map(player,"down",0) then
  player.landed=true
  player.falling=false
  player.dy=0
  player.y-=((player.y+player.h+1)%8)-1
end

elseif player.dy<0 then
player.jumping=true
if collide_map(player,"up",1) then
player.dy=0
end
end

--check collision left and right
if player.dx<0 then

player.dx=limit_speed(player.dx,player.max_dx)

if collide_map(player,"left",1) then
  player.dx=0
end

elseif player.dx>0 then

player.dx=limit_speed(player.dx,player.max_dx)

if collide_map(player,"right",1) then
  player.dx=0
end

end

--stop sliding
if player.sliding then
if abs(player.dx)<.2
or player.running then
player.dx=0
player.sliding=false
end
end

player.x+=player.dx
player.y+=player.dy

--limit player to map
if player.x<map_start then
player.x=map_start
end
if player.x>map_end-player.w then
player.x=map_end-player.w
end
end

function player_animate()
if player.jumping then
player.sp=7
elseif player.falling then
player.sp=8
elseif player.sliding then
player.sp=9
elseif player.running then
if time()-player.anim>.07 then
player.anim=time()
player.sp+=1
if player.sp>6 then
player.sp=3
end
end
else --player idle
if time()-player.anim>.3 then
player.anim=time()
player.sp+=1
if player.sp>2 then
player.sp=1
end
end
end
end

function limit_speed(num,maximum)
return mid(-maximum,num,maximum)
end

--attempting to climb
function player_climbing()
if collide_map(player,"right",2)
and btn(❎) and btn(⬆️)
then player.y+=500
end
end

flag 2 is meant to be climbable walls.
should this not increase my vertical velocity by 5?

P#149731 2024-06-10 07:22

The code is increasing your y position by 500, not your velocity by 5. Also, positive y is downwards, so you’d be teleporting 500 pixels downwards.

P#149734 2024-06-10 07:43

thanks soupster. forgot to edit the code from when I was seeing if any result occurred (if the code worked, could change y to much less than 500). i changed player.y+=500 to player.dy-=5, and it still didn't work

P#149735 2024-06-10 08:25

We're missing part of the picture : there's no code calling player_climbing() in your post. Could you post a WIP cart instead ?

P#149738 2024-06-10 09:54

Cart #sigopewoda-0 | 2024-06-10 | Code ▽ | Embed ▽ | No License

P#149740 2024-06-10 10:43

Cart #bidizebeso-0 | 2024-06-10 | Code ▽ | Embed ▽ | No License

The call to player_climbing() was indeed missing.
the function itself had a sign error (Y axis goes down as y increases)
The keys tested for wall climb are up+O simultaneously, this might not be what you intended.
Remarks : the X and Y coordinates are not integer, for a more accurate display, 0.5 should be added to the X and Y to compensate for the truncation of the fractional part.
When moving horizontally into a wall, the X should be snapped the the proper integer value so the player can touch the wall.
tab 1 line 50 you can set debug to false to stop the coordinates display over the player sprite.

P#149747 2024-06-10 12:57

[Please log in to post a comment]