At first the lerp still jumped from one to the other and not gradually. Then I realized my fwd_mps
was int(fwd_mpsf)
. But apparantly the weight isn't only from 0 to 1, only the portion between from and to value. At first I thought it was strange I had an FOV of 25, while nowhere in my code I had assigned such a value. Then I noticed that it was because the scaling was -3. If FOV 70 was at 120km/h, then at 0km/h it was 25.
Since with boosting the car goes over the max_speed, the FOV automatically also goes beyond my max_FOV.
I also did have to address sudden drops in speed because of driving against something that stopped me, otherwise the FOV kept going smaller.
func _physics_process(delta):
...
var current_speed = follow_this.fwd_mpsf
min_speed = 120
max_speed = 200
speed_scale = (current_speed - min_speed) / (max_speed - min_speed)
if (current_speed > min_speed):
set_fov(lerp(min_FOV, max_FOV, speed_scale))
target_distance = lerp(min_cam_distance, max_cam_distance, speed_scale)
target_height = lerp(min_cam_height, max_cam_height, speed_scale)
elif (get_fov() > min_FOV or (follow_this.handbrake and get_fov() > min_FOV)):
set_fov(get_fov() - delta * 7)
target_distance = lerp(target_distance, 4.0, spdChangeFOV)
target_height = lerp(target_height, 1.0, spdChangeFOV)
So at last this works as I initially wanted it to. Funny how trying to find a solution for one thing happens to give the solution for something else.
There is one "beauty" error I get with this. Since I have an if-statement to not go over a certain speed, at the end, when accelerate is pressed, it constantly jumps from 199 to 200... this is also slightly visible in the FOV.
Tried to make the FOV integers, but that only made the transition jittery.
I also used the code of the FOV for the engin_force. since I'm still not able to figure out how to remove the drag from driving uphill or turning. So I just give a high value engine_force at the lower speeds and gradually turn it down, so if I want to drive uphill from a standstill, it has the force to do so.
So still one thing to figure out is how to rotate the camera looking left or right only when the joystick is held down to either fully left or right (= -1 or 1) for 2 or 3 seconds.
I noticed doing the rotating based on the speed of the car is useless. I just need to rotate it on a given angle and transition it smoothly of a set time. And go smoothly back to the 0 rotation if the joystick is released.
Currently I have:
func get_input(delta):
if (!keyb):
look_around = Input.get_action_strength("turn_left") - Input.get_action_strength("turn_right")
var scale_looking = follow_this.fwd_mpsf / 3
if (abs(look_around) == 1.0):
rotate_object_local(Vector3.UP, lerp(0, scale_looking * look_around, delta))
The scale_looking is useless here, I think. Probably need to use a tween here? Or is it possible with a Timer/time, that maybe also can check if the joystick is held more than x amount of seconds? I also saw something about lerp_angle in the Help, but that code gives strange results.
After that, It's time to upload a new video about the progress.