# How to simulate movement in 3d?

Hello all,
My friend and I are going to be making a game in 3d eventually. I have meshes down but was wondering how to simulate movement in 3d. For example, if I wanted to move forwards and have the meshes move about accordingly, what arguments to the ‘camera’, ‘translate’, ‘rotate’, or perhaps ‘perspective’ functions would I modify. I have been experimenting, but nothing really has worked out. At first I thought to modify just the x and y camera functions but that has not worked out. Can anyone tell me how I can do this?
Thank you.
P.S. I know there might be a discussion like this out there somewhere, but I could not find it.

I would recommend reading through Ignatz’s guides, they have certainly helped me and many others to gain some understanding of many elements of Codea. Here is a link to the posts on 3D - https://coolcodea.wordpress.com/category/3d/. Good luck.

I have a W.I.P. class for easy camera positioning and rotation, if you want to try it.

``````Cam3D = class()

function Cam3D:init()
self.pos = vec3(0, 5, 0)
self.rot = vec3(90, 0, 0)
self.fov = 45
self.clip = 8192
end

function Cam3D:pose()
local dy = math.cos(math.rad(self.rot.x))
local xzMult = 1 - math.abs(math.cos(math.rad(self.rot.x)))
local dx, dz = math.sin(math.rad(self.rot.y)) * xzMult, math.cos(math.rad(self.rot.y)) * xzMult
local upx = math.sin(math.rad(self.rot.z + self.rot.y))
local upy = math.cos(math.rad(self.rot.z))
local upz = math.cos(math.rad(self.rot.z + self.rot.y))
camera(self.pos.x, self.pos.y, self.pos.z, self.pos.x + dx, self.pos.y + dy, self.pos.z + dz, upx, upy, upz)
perspective(self.fov, WIDTH / HEIGHT, 0.01, self.clip)
end
``````

Just set its `pos` and `rot` values, that’s all you really need.

Known bug: Camera goes backwards when you look up too high. I’m working on a fix.