Math Help - Car MPH

Godot Version

4.6.2

Question

I am very lost on Vector math. I have tried to learn it but I just don’t understand it. The reason this arises is I am trying to make a camera nodes FOV increase with a curve based on the MPH of the car. I have no idea how I would normalize. So. I can sample a curve.

class_name CarComponent
extends Node

@export var car : VehicleBody3D

@export var speed := 100.0
@export var turn_amount := 0.3

var move_dir := Vector2.ZERO

func car_update(delta: float):
	car.engine_force = speed * move_dir.y
	car.steering = move_toward(car.steering, (turn_amount * move_dir.x), delta)

func get_mph() -> float:
	var mps = car.linear_velocity.length()
	var mph = mps * 2.237
	return mph

class_name CameraComponent
extends Camera3D

@export var fov_curve : Curve
var mph := 0.0

The camera component has much less as I am struggling a lot on the math.

Why do you need to normalize? You can set curve’s domain to your mph range.

If you still want to normalize it, just divide it with maximal mph.

I looked things up and found

class_name CameraComponent
extends Camera3D

@export var fov_curve : Curve
@export var max_fov := 100.0
@export var min_fov := 70.0
var mph := 0.0

func camera_update():
	var fov_multiplier = fov_curve.sample(sigmoid(mph))
	fov = max_fov * fov_multiplier
	fov = clamp(fov, min_fov, max_fov)

func sigmoid(x):
	return 1 / (1 + exp(-x))

It works so I will keep this

I should have explained better thats my bad. I have having trouble getting the MPH range.

If the range is unknown then using the logistic function as you do is a good approach. You might still want to scale the domain so that the curve doesn’t go to its maximal value of 1.0 too early.

Thank you.