The character doesn't rotate, only its visual does. I made it follow the Y rotation just as an example. You'll notice that the root node only moves, it's not meant to rotate already, so the camera and the character visual can have their own rotations.
So to fix this you have to modify the rotation of the visual
, not the root node itself (which only needs to be moved).
I updated your code and it works now:
if(motion != Vector3()):
# Used atan2 but you can also use Vector2(motion.x, -motion.z).angle()
var angle = atan2(motion.x, -motion.z)
print("target angle is::", round(rad2deg(angle)), " (", str(motion), ")")
Rotation(angle);
# This cannot work because lerp on an angle will not choose the shortest arc
# var body_rot = visual.get_rotation()
# body_rot.y = lerp(body_rot.y, angle, 5 * delta)
# visual.set_rotation(Vector3(body_rot.x, body_rot.y, body_rot.z))
func Rotation(var angle):
var delta = get_fixed_process_delta_time()
var current_rot = Quat(visual.get_transform().basis)
var target_rot = Quat(Vector3(0,1,0), angle)
var smooth_rot = current_rot.slerp(target_rot, delta * 5)
visual.set_rotation(Matrix3(smooth_rot).get_euler())
Alternatively, if you want the camera to be completely separated from the character, you can move it outside of the character tree, which needs the commented section to be activated in tps_camera.gd
(see previous post) and the target
property to be set.