diff --git a/project.godot b/project.godot index e9d494a..b6781bc 100644 --- a/project.godot +++ b/project.godot @@ -43,6 +43,11 @@ _global_script_classes=[ { "class": "TracksFactory", "language": "GDScript", "path": "res://scripts/road/roads_factory.gd" +}, { +"base": "Node", +"class": "Util", +"language": "GDScript", +"path": "res://scripts/Util.gd" } ] _global_script_class_icons={ "BasePathPlayer": "", @@ -51,7 +56,8 @@ _global_script_class_icons={ "Preview": "", "Road": "", "Route": "", -"TracksFactory": "" +"TracksFactory": "", +"Util": "" } [application] @@ -64,6 +70,7 @@ config/icon="res://icon.png" game_state="*res://scripts/game/game_state.gd" roads_factory="*res://scripts/road/roads_factory.gd" +Util="*res://scripts/Util.gd" [input] diff --git a/scenes/player/BasePathPlayer.tscn b/scenes/player/BasePathPlayer.tscn index c0e93b4..793ada2 100644 --- a/scenes/player/BasePathPlayer.tscn +++ b/scenes/player/BasePathPlayer.tscn @@ -76,7 +76,7 @@ shape = SubResource( 3 ) transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0.3, -0.6 ) [node name="ray" type="RayCast" parent="Path/PathFollow/raceCar"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.075, 0.174408 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.075, 0.2 ) enabled = true cast_to = Vector3( 0, -0.2, 0 ) diff --git a/scripts/Util.gd b/scripts/Util.gd new file mode 100644 index 0000000..31dd085 --- /dev/null +++ b/scripts/Util.gd @@ -0,0 +1,6 @@ +extends Node + +class_name Util + +static func Curve_get_last_point(curve:Curve3D): + return curve.get_point_position(curve.get_point_count() - 1) diff --git a/scripts/player/BasePathPlayer.gd b/scripts/player/BasePathPlayer.gd index 780a6a2..c8a4d83 100644 --- a/scripts/player/BasePathPlayer.gd +++ b/scripts/player/BasePathPlayer.gd @@ -46,6 +46,8 @@ func _physics_process(delta): if has_next && (path.curve.get_point_count() == 0 || follow.get_unit_offset() >= 1.0): has_next = false path.curve.clear_points() + if path.curve == null: + path.curve = Curve3D.new() for i in range(buffered_curve.get_point_count()): var _pos = buffered_curve.get_point_position(i) var _in = buffered_curve.get_point_in(i) @@ -61,6 +63,9 @@ func _physics_process(delta): if get_road() != null: road_index = get_road().get_index() + print(buffered_translate) + print(buffered_curve.get_baked_length()) + print(path.curve.get_baked_length()) if get_road() != null: var road = get_road() var penalty_index = road.penalty_index(follow.get_offset(), current_speed) @@ -94,18 +99,19 @@ func get_road(): return get_race_car().road func _on_raceCar_road_entered(road): - print(road.get_name()) buffered_curve = road.get_lane_curve(lane) + print(road.get_name()) + print(buffered_curve.get_baked_length()) buffered_rotation_axis = last_rotation_axis buffered_rotation_phi = last_rotation_phi if path.curve.get_point_count() > 0: - buffered_translate = path.curve.get_point_position(path.curve.get_point_count() - 1) + buffered_translate = Util.Curve_get_last_point(path.curve) if road.get_end_rotation_phi() != 0: last_rotation_axis = (last_rotation_axis + road.get_end_rotation_axis()).normalized() - last_rotation_phi = last_rotation_phi + road.get_end_rotation_phi() + last_rotation_phi += road.get_end_rotation_phi() has_next = true @@ -138,7 +144,7 @@ master func reset(): if road_before == null: road_before = road - buffered_translate = road.get_translation() + #buffered_translate = road_before.get_curve().get_point_position(road_before.get_curve().get_point_count() - 1) last_rotation_axis = road_before.get_rotation().normalized() last_rotation_phi = road_before.get_rotation().length() diff --git a/scripts/road/road.gd b/scripts/road/road.gd index 7bceb0d..945d9d0 100644 --- a/scripts/road/road.gd +++ b/scripts/road/road.gd @@ -81,14 +81,19 @@ func get_torque_penalty(index:int): if index >= 0: while torque_penalties.size() < (index + 1): index-=1 - return torque_penalties[index] - + if get_rotation().length() != 0: + return torque_penalties[index].rotated(get_rotation().normalized(), get_rotation().length()) + else: + return torque_penalties[index] return Vector3(0,0,0) func get_force_penalty(index:int): if index >= 0: while force_penalties.size() < (index + 1): index-=1 - return force_penalties[index] + if get_rotation().length() != 0: + return force_penalties[index].rotated(get_rotation().normalized(), get_rotation().length()) + else: + return force_penalties[index] return Vector3(0,0,0) \ No newline at end of file