Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

Raycasting bends the World wierdly. PICO-8. (LUA)

I am trying to make a Wolfenstein3D-like game, using pico-8 (that's a 2d engine with many limitations) and the world just bends very weirdly.

Gif of running around

My code: (Warning LUA! Confusing language. starts counting at 1...! )

function ray_cast()
  points = {}
  for i=1,64 do
    points[i] = -1
  end


  for o = -31,32 do
    local angle = player.lvec - o/256
    
    
    for i=0,96 do
      local x,y
      x = i * cos(angle)
      y = i * sin(angle)
    
      if mget((x+player.x)/8,(y+player.y)/8) == 1 then
            
        local tx = i-1 * cos(angle)
        local ty = i-1 * sin(angle)
            
        local dis = sqrt((tx^2+ty^2)) 
            
        points[o+32] = dis*cos(angle-player.lvec)
        break
      end
    end
  end
end

I asked for help in the PICO-8 discord and someone said they could help me, but after a lot of messaging, it still did not result in the solution I wanted.

Edit: New GIF Distortion of things


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't know the language of Lua, however, I do understand the basics of ray-casting. From what I see, the issue could be a too large FOV size or the angles not being fixed (subtracting 360 degrees/2PI radians when above 360 degrees/2PI radians, or adding 360 degrees/2PI radians when below 0). If you don't "fix" the angles, you may get incorrect ray hit positions or even in some cases, crash the GUI. If you have a large FOV, the world will appear to be warped.

FOV OF 64 DEGREES:

FOV OF 128 DEGREES: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...