Hello all, recently I was working in 3d and i whipped together this in a few minutes:
-- Into the Thid Dimension
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
walls=mesh()
verts={
vec3(25,0,25),
vec3(25,0,-25),
vec3(-25,0,25),
vec3(-25,0,-25),
vec3(25,25,25),
vec3(25,25,-25),
vec3(-25,25,25),
vec3(-25,25,-25)
}
tex={
vec2(1,1),
vec2(0,0),
vec2(1,0),
vec2(0,1)
}
walls.vertices={
verts[1],verts[5],verts[3],
verts[3],verts[7],verts[5],
verts[3],verts[7],verts[4],
verts[4],verts[8],verts[7],
verts[2],verts[6],verts[4],
verts[4],verts[8],verts[6],
verts[1],verts[5],verts[2],
verts[2],verts[6],verts[5]
}
walls.texCoords={
tex[3],tex[1],tex[2],
tex[2],tex[4],tex[1],
tex[3],tex[1],tex[2],
tex[2],tex[4],tex[1],
tex[3],tex[1],tex[2],
tex[2],tex[4],tex[1],
tex[3],tex[1],tex[2],
tex[2],tex[4],tex[1]
}
walls.texture="Cargo Bot:Game Area"
walls:setColors(255,255,255)
floor=mesh()
floor.vertices={
verts[1],verts[2],verts[4],
verts[1],verts[3],verts[4]
}
floor.texCoords={
tex[1],tex[3],tex[2],
tex[1],tex[4],tex[2]
}
floor.texture="Documents:floor"
look=vec3(0,1,0)
pos=vec2(0,0)
angle=vec2(0,1)
touches={}
b=Button(50,50,50,50)
acc=vec2(0,0)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
b:draw()
pushMatrix()
pos=pos-acc
look.x,look.z=math.sin(math.rad(angle.x))*1,-math.cos(math.rad(angle.x))*1
look.y=math.sin(math.rad(angle.y))*10
perspective(45,WIDTH/HEIGHT)
camera(pos.x,1,pos.y,look.x,look.y,look.z,0,1,0)
walls:draw()
floor:draw()
popMatrix()
for i,v in pairs(touches) do
if v.x<b.x or v.x>b.x+b.w or v.x<b.y or v.x>b.y+b.h then
angle.x=angle.x+v.deltaX/100
angle.y=angle.y+v.deltaY/100
else acc=(vec2(pos.x,pos.z)-vec2(look.x,look.z)):normalize()
end
end
end
function touched(t)
if t.state~=ENDED and t.state~=CANCELLED then
touches[t.id]=t
else
touches[t.id]=nil
acc=vec2(0,0)
end
end
For some reason, it is not working, for movement seems to move in a random direction and whenever I do move a little bit, the direction one is looking in also gets messed up. Does anyone know how to fix this? Thank you!
-TheSolderKing