Reminder: Codea 3.x has built in entity transformations to determine orientation in local space-- handy for 3D FPS movement!

Hello, Everyone.

I’ve been searching for a while to see if I could make my 3D FPS movement code simpler. Specifically, I was looking for a function that would help me when I wanted to move 3D FPS scene.camera moves off of one of the XYZ axis such as moving the camera “forward” in relationship to where the camera is pointing off-axis. Unity has a “transform.forward” command and was trying to accomplish the same thing with quaternion * vector but couldn’t figure out how to do so. However, I recently found an old post on the forum by @RonJeffries where he found same code that @John had put into the Craft Camera project, and it turns out Codea does have similar functionality! You can use:

Entity.forward, Entity.right, or Entity.up (or conversely - * these directions).
So, if your camera is pointing an arbitrary off-axis angle in 3D, and you want to move the camera 5 units forward, you can just do:

scene.camera.position = scene.camera.position + (scene.camera.forward * 5)

I found that simplified my 3D movement code, and is helping me on a new 3D project where I’m working on a 3D person movement and needing to place the camera a constant distance behind and above and object and have the ability to then detach it from that object and move to another object to follow that object.

This is the simplified draw function using Codea 3.x current functionality:

function draw()
update(DeltaTime)
ax = ax + axspeed
ay = ay + ayspeed
az = az + azspeed
scene.camera.position = scene.camera.position + (scene.camera.forward * czspeed)
scene.camera.eulerAngles = vec3(ax, ay, az)
scene:draw()
drawButton()
end

Where ax, ay, az are eulerAngle variables for camera rotation (modified by the scalar variables axspeed, ayspeed, azspeed to determine the speed of the rotation along the different local axes) and czspeed is the speed(units) one wants to set the forward movement. The drawButton() function is from @dave1707’s button GUI that he previously created to control 3D FPS movement

@John mentioned in a previous post that he was planning such transforming 3D movement functionality in Codea 4.x but thought others might want to know about this feature now that is not documented in the Codea 3.x documentation.

Fyi :slight_smile:

1 Like