I am trying to implement a third person camera in lua, and so far I have managed to rotate the camera view, follow the player, and move. The problem comes with rotating the player and moving in the camera direction.
I tried getting the camera rotation quaternion and multiply by the movement vector, but the player shakes, jumps and do all kind of styff except moving in the right direction. Havent tried to rotate the model yet.
What can you recommend to implement this?
#Implementing 3rd person camera in lua
1 messages · Page 1 of 1 (latest)
Create normalized cam_forward and cam_right vector with the cameras BasisZ and BasisX (make sure to set y to zero for both of them), then multiply them by your vertical and horizontal input values and add them together to create a movement vector relative to the camera look direction.
Then just rotate the character to that normalized vector by using CreateLookAt() to create a target rotation from the players current rotation.
Note that I haven't actually done this in O3DE but this is generally what how I've handled 3rd person character movement in other engines
Also make sure your camera is not a child of your character. That might be why your player is behaving erratically when you try to rotate it.
Problem is that seems that get forward and get right are not exposed to Lua (they are to ScriptCanvas) or I cant find them. Thats why I got the World Rotaiton as a quaternion. And yes, the camera entity is independent from the player entity, it just follows it.
try Transform.GetBasisZ() and Transform.GetBasisX()
Wait the forward axis should be Y in O3DE so use GetBasisY instead of GetBasisZ
`current_cam_tm = TransformBus.Event.GetWorldTM(cam)
cam_fwd = Transform.GetBasisY(current_cam_tm)
cam_fwd.z = 0
cam_rgt = Transform.GetBasisX(current_cam_tm)
cam_rgt.z = 0
self.Properties.look_target = (cam_rgt*input_rgt) + (cam_fwd*input_fwd)
current_pos = TransformBus.Event.GetWorldTranslation(self.entityId)
move_to = current_pos + (self.Properties.look_target)*0.1
TransformBus.Event.SetLocalTranslation(self.entityId, move_to)`
I just slapped that together and it worked. I'm new to lua scripting so i don't kknow exactly what im doing, but at least this works currently in O3DE
I didnt add camera rotation but the character was moving relative to the stationary camera.