From 892ed4854bcccbac546f5ac32c0c5fa0245f5fa7 Mon Sep 17 00:00:00 2001 From: perivesta <> Date: Sat, 8 Jul 2023 11:40:53 +0200 Subject: draw a path for car to follow --- Scripts/car_behaviour.gd | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Scripts/car_behaviour.gd') diff --git a/Scripts/car_behaviour.gd b/Scripts/car_behaviour.gd index b71ebb6..afbc32f 100644 --- a/Scripts/car_behaviour.gd +++ b/Scripts/car_behaviour.gd @@ -5,6 +5,7 @@ extends StaticBody2D @export var steer_force = 0.1 @export var look_ahead = 75 @export var num_rays = 32 +@export var driving = false # context array var ray_directions = [] @@ -28,6 +29,9 @@ func _ready(): func _physics_process(delta): + if not driving: + return + set_interest() set_danger() choose_direction() @@ -38,8 +42,12 @@ func _physics_process(delta): func set_interest(): # Set interest in each slot based on world direction - if owner and owner.has_method("get_path_direction"): - var path_direction = owner.get_path_direction(position) +# if owner and owner.has_method("get_path_direction"): + if owner and owner.has_method("get_path_next_position"): +# var path_direction = owner.get_path_direction(position) + var next_pos = owner.get_path_next_position(position) + var path_direction = (next_pos - position).normalized() + for i in num_rays: var d = ray_directions[i].rotated(rotation).dot(path_direction) interest[i] = max(0, d) -- cgit