tried adding guide lines
This commit is contained in:
parent
7735245b05
commit
82bfc1d184
6 changed files with 115 additions and 46 deletions
|
@ -28,7 +28,7 @@ window/stretch/mode="canvas_items"
|
|||
2d_physics/layer_1="walls"
|
||||
2d_physics/layer_2="walldetection"
|
||||
2d_physics/layer_3="Marking"
|
||||
2d_physics/layer_4="Layer 4"
|
||||
2d_physics/layer_4="roadguide"
|
||||
|
||||
[rendering]
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
[ext_resource type="TileSet" uid="uid://carpfxq3rn3aa" path="res://sprites/spritesheet_htrohr/htrohr.tres" id="5_748hi"]
|
||||
[ext_resource type="Texture2D" uid="uid://dpuhee0x5ekud" path="res://sprites/background/spritesheet_scenery.png" id="5_lefrm"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_qbu02"]
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_fam2n"]
|
||||
texture = ExtResource("1_8lp8c")
|
||||
texture_region_size = Vector2i(256, 256)
|
||||
0:0/0 = 0
|
||||
|
@ -44,7 +44,7 @@ texture_region_size = Vector2i(256, 256)
|
|||
|
||||
[sub_resource type="TileSet" id="TileSet_5knbn"]
|
||||
tile_size = Vector2i(256, 256)
|
||||
sources/1 = SubResource("TileSetAtlasSource_qbu02")
|
||||
sources/1 = SubResource("TileSetAtlasSource_fam2n")
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_daqun"]
|
||||
size = Vector2(23, 317)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -81,8 +81,7 @@ var burnout:float=0 #at 0 is off
|
|||
|
||||
@onready var ray_cast_fl: RayCast2D = $RayCast_FL
|
||||
@onready var ray_cast_fr: RayCast2D = $RayCast_FR
|
||||
@onready var ray_cast_car_fl: RayCast2D = $RayCast_Car_FL
|
||||
@onready var ray_cast_car_fr: RayCast2D = $RayCast_Car_FR
|
||||
|
||||
|
||||
@onready var reset_timer: Timer = $resetTimer
|
||||
|
||||
|
@ -175,36 +174,43 @@ func get_input(delta:float):
|
|||
const distance_inf=1000
|
||||
var distance_fl=distance_inf
|
||||
var distance_fr=distance_inf
|
||||
var distance_guide_l=0
|
||||
var distance_guide_r=0
|
||||
|
||||
if ray_cast_fl.is_colliding():
|
||||
var origin=ray_cast_fl.global_transform.origin
|
||||
var collision_point = ray_cast_fl.get_collision_point()
|
||||
distance_fl = origin.distance_to(collision_point)
|
||||
var collision_object=ray_cast_fl.get_collider()
|
||||
#if collision_object.name==ROAD_R_NAME:
|
||||
if collision_object.name==ROAD_R_NAME:
|
||||
distance_fl*=2 #fake distance when wrong side of road
|
||||
|
||||
#print("DistanceFL "+str(distance_fl))
|
||||
if ray_cast_fr.is_colliding():
|
||||
var origin=ray_cast_fr.global_transform.origin
|
||||
var collision_point = ray_cast_fr.get_collision_point()
|
||||
distance_fr = origin.distance_to(collision_point)
|
||||
var collision_object=ray_cast_fr.get_collider()
|
||||
if collision_object.name==ROAD_L_NAME:
|
||||
distance_fr*=2 #fake distance when wrong side of road
|
||||
#print("DistanceFR "+str(distance_fr))
|
||||
|
||||
|
||||
|
||||
var distance_min= min(distance_fl,distance_fr)
|
||||
|
||||
|
||||
var turndirection = 1 if distance_fl<distance_fr else -1
|
||||
|
||||
var steering_angle=constrain( remap(velocity.length(),steering_speed_fast,steering_speed_slow,steering_angle_fast,steering_angle_slow),steering_angle_fast,steering_angle_slow) #set maximum steering_angle based on speed
|
||||
|
||||
var steering_distance_far=constrain( remap(velocity.length(),steering_speed_fast,steering_speed_slow,steering_distance_far_fast,steering_distance_far_slow),steering_distance_far_fast,steering_distance_far_slow)
|
||||
var steering_distance_close=constrain( remap(velocity.length(),steering_speed_fast,steering_speed_slow,steering_distance_close_fast,steering_distance_close_slow),steering_distance_close_fast,steering_distance_close_slow)
|
||||
|
||||
|
||||
steer_direction=0 #0=straight
|
||||
if autosteer_enabled:
|
||||
if distance_min<steering_distance_far: #wall close, start steering away
|
||||
steer_direction = turndirection*deg_to_rad(constrain(remap(distance_min,steering_distance_far,steering_distance_close,0,steering_angle), 0,steering_angle))
|
||||
else:
|
||||
steer_direction=0 #drive straight
|
||||
steer_direction += turndirection*deg_to_rad(constrain(remap(distance_min,steering_distance_far,steering_distance_close,0,steering_angle), 0,steering_angle))
|
||||
|
||||
|
||||
|
||||
applied_engine_power=0
|
||||
|
||||
|
|
14
scripts/line_2d_collision.gd
Normal file
14
scripts/line_2d_collision.gd
Normal file
|
@ -0,0 +1,14 @@
|
|||
extends Line2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var staticbody:StaticBody2D=get_child(0)
|
||||
$".".visible=false
|
||||
|
||||
|
||||
var line_poly=Geometry2D.offset_polyline(points,width/2)
|
||||
|
||||
for poly in line_poly:
|
||||
var col = CollisionPolygon2D.new()
|
||||
col.polygon=poly
|
||||
staticbody.add_child(col)
|
Loading…
Reference in a new issue