Hi,
in trying to get my camera to look around the car with the analog right stick through kidscancode camera gimbal solution, (which I still can seem to get implemented on my camera), I stumbled on the solution I had a few weeks ago I couldn't get working, in the form of the nice rotate_object_local().
I wanted the camera to look with you when turning. So the camera would point towards the left or right on you, depending on which direction you turned. I got that working now, but the screen jitters. I think I know why that is, but I just don't know how to rectify it.
https://youtu.be/mUKp8n1qoo4
Here is the script I currently have (I reverted back to a simple follow player script for now):
func _ready():
follow_this = get_node(follow_this_path)
last_lookat = follow_this.global_transform.origin
func _physics_process(delta):
var target = follow_this.global_transform.origin
var pos = global_transform.origin
var up = Vector3(0,1,0)
var offset = pos - target
offset = offset.normalized() * target_distance
offset.y = target_height
pos = target + offset
look_at_from_position(pos, target, up)
func _process(delta: float) -> void:
get_input(delta)
if (follow_this.boost):
currentFOV = boostFOV
else:
currentFOV = maxFOV
if (follow_this.fwd_mps > 150):
if (get_fov() < currentFOV):
set_fov(get_fov() + delta * 7)
target_distance = lerp(target_distance, 3.0, spdChangeFOV)
target_height = lerp(target_height, 0.5, spdChangeFOV)
else:
if (get_fov() > minFOV):
set_fov(get_fov() - delta \* 7)
target_distance = lerp(target_distance, 4.0, spdChangeFOV)
target_height = lerp(target_height, 1.0, spdChangeFOV)
func get_input(delta):
look_around = Input.get_action_strength("turn_left") - Input.get_action_strength("turn_right")
var scale_looking = follow_this.fwd_mpsf / 300
rotate_object_local(Vector3.UP, look_around * scale_looking)