Car AI Not Working

Godot Version

4.6.2

Question

I am having trouble getting my car AI to run itself into the player.

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
var braking := false

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

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

class_name NavComponent
extends NavigationAgent3D

var player : Player
var wanted_dir := Vector2.ZERO

func _ready() -> void:
	player = get_tree().get_first_node_in_group("Player")

func nav_update():
	update_target_location(player.global_position)
	var current_location = owner.global_position
	var next_location = get_next_path_position()
	
	var dir = owner.to_local(next_location - current_location)
	wanted_dir = Vector2(dir.x, dir.z)

func update_target_location(target_location):
	set_target_position(target_location)

I assume its just math I need to fix. If it is please explain why :slight_smile:

Please explain the trouble you are seeing.

Its getting really close to the player car than turning away. Running away from the player or spinning it a circle.