Taehl wrote:The scale is 1 - each tile is 1 cubic meter. For sake of simplicity, let's assume the player is also 1 cubic meter.
So you're saying I'm going to have to go from 1 check per step to 8 checks per step? Can we reduce this? The player's collision shape could be a sphere or something if it would make calculations any simpler
We can easily turn the player into a cylinder. To check that, you have to have the 8 points of each cube, though. Lol. It also takes 8 points for the sphere....
Anyway, I have absolutely no idea how your code works... It looks like you're checking for the nearest cube in the path of the player. @_@
I don't want to write some function to get the nearest cubes, so I'll assume it's getNearestBlocks(), which returns a table of tables with 3 values labeled x,y, and z.
Code: Select all
local p = player
local mx, my, hit = 0, 0, false
local speed = kshift and 0.1 or 0.05 -- kw, ka, ks, kd, and kshift are keyboard buttons
if kw then mx = mx-speed my = my-speed end
if ks then mx = mx+speed my = my+speed end
if ka then my = my-speed mx = mx+speed end
if kd then my = my+speed mx = mx-speed end
if (kw or ks) and (ka or kd) then mx, my = mx/2, my/2 end -- Diagonal movement isn't faster
-- You should probably be dividing by sqrt(2), unless the slow down is intentional.
local z,x,y=checkCollision(p.z,p.x+mx,p.y+my)
p.x=p.x+(x and 0 or mx)
p.y=p.y+(y and 0 or my)
function trace(z,x,y)
local x1,y1,z1=x-.5,y-.5,z-.5
local x2,y2,z2=x+.5,y-.5,z-.5
local x3,y3,z3=x+.5,y-.5,z+.5
local x4,y4,z4=x-.5,y-.5,z+.5
local x5,y5,z5=x-.5,y+.5,z-.5
local x6,y6,z6=x+.5,y+.5,z-.5
local x7,y7,z7=x+.5,y+.5,z+.5
local x8,y8,z8=x-.5,y+.5,z+.5
local xc,yc,zc=false,false,false
for _,v in pairs(getNearestBlocks()) do
local v1x,v1y,v1z=v.x-.5,v.y-.5,v.z-.5
local v2x,v2y,v2z=v.x+.5,v.y+.5,v.z+.5
if x1>v1x and x1<v2x or
x2>v1x and x2<v2x or
x3>v1x and x3<v2x or
x4>v1x and x4<v2x or
x5>v1x and x5<v2x or
x6>v1x and x6<v2x or
x7>v1x and x7<v2x or
x8>v1x and x8<v2x then
xc=true
end
if y1>v1y and y1<v2y or
y2>v1y and y2<v2y or
y3>v1y and y3<v2y or
y4>v1y and y4<v2y or
y5>v1y and y5<v2y or
y6>v1y and y6<v2y or
y7>v1y and y7<v2y or
y8>v1y and y8<v2y then
yc=true
end
if z1>v1z and z1<v2z or
z2>v1z and z2<v2z or
z3>v1z and z3<v2z or
z4>v1z and z4<v2z or
z5>v1z and z5<v2z or
z6>v1z and z6<v2z or
z7>v1z and z7<v2z or
z8>v1z and z8<v2z then
zc=true
end
end
return xc,yc,zc
end