Browse Source

fixing penalty rotation

Lurkars 6 years ago
parent
commit
59c093b3df
  1. 9
      project.godot
  2. 2
      scenes/player/BasePathPlayer.tscn
  3. 6
      scripts/Util.gd
  4. 14
      scripts/player/BasePathPlayer.gd
  5. 7
      scripts/road/road.gd

9
project.godot

@ -43,6 +43,11 @@ _global_script_classes=[ {
"class": "TracksFactory", "class": "TracksFactory",
"language": "GDScript", "language": "GDScript",
"path": "res://scripts/road/roads_factory.gd" "path": "res://scripts/road/roads_factory.gd"
}, {
"base": "Node",
"class": "Util",
"language": "GDScript",
"path": "res://scripts/Util.gd"
} ] } ]
_global_script_class_icons={ _global_script_class_icons={
"BasePathPlayer": "", "BasePathPlayer": "",
@ -51,7 +56,8 @@ _global_script_class_icons={
"Preview": "", "Preview": "",
"Road": "", "Road": "",
"Route": "", "Route": "",
"TracksFactory": ""
"TracksFactory": "",
"Util": ""
} }
[application] [application]
@ -64,6 +70,7 @@ config/icon="res://icon.png"
game_state="*res://scripts/game/game_state.gd" game_state="*res://scripts/game/game_state.gd"
roads_factory="*res://scripts/road/roads_factory.gd" roads_factory="*res://scripts/road/roads_factory.gd"
Util="*res://scripts/Util.gd"
[input] [input]

2
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 ) 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"] [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 enabled = true
cast_to = Vector3( 0, -0.2, 0 ) cast_to = Vector3( 0, -0.2, 0 )

6
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)

14
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): if has_next && (path.curve.get_point_count() == 0 || follow.get_unit_offset() >= 1.0):
has_next = false has_next = false
path.curve.clear_points() path.curve.clear_points()
if path.curve == null:
path.curve = Curve3D.new()
for i in range(buffered_curve.get_point_count()): for i in range(buffered_curve.get_point_count()):
var _pos = buffered_curve.get_point_position(i) var _pos = buffered_curve.get_point_position(i)
var _in = buffered_curve.get_point_in(i) var _in = buffered_curve.get_point_in(i)
@ -61,6 +63,9 @@ func _physics_process(delta):
if get_road() != null: if get_road() != null:
road_index = get_road().get_index() 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: if get_road() != null:
var road = get_road() var road = get_road()
var penalty_index = road.penalty_index(follow.get_offset(), current_speed) var penalty_index = road.penalty_index(follow.get_offset(), current_speed)
@ -94,18 +99,19 @@ func get_road():
return get_race_car().road return get_race_car().road
func _on_raceCar_road_entered(road): func _on_raceCar_road_entered(road):
print(road.get_name())
buffered_curve = road.get_lane_curve(lane) 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_axis = last_rotation_axis
buffered_rotation_phi = last_rotation_phi buffered_rotation_phi = last_rotation_phi
if path.curve.get_point_count() > 0: 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: if road.get_end_rotation_phi() != 0:
last_rotation_axis = (last_rotation_axis + road.get_end_rotation_axis()).normalized() 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 has_next = true
@ -138,7 +144,7 @@ master func reset():
if road_before == null: if road_before == null:
road_before = road 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_axis = road_before.get_rotation().normalized()
last_rotation_phi = road_before.get_rotation().length() last_rotation_phi = road_before.get_rotation().length()

7
scripts/road/road.gd

@ -81,14 +81,19 @@ func get_torque_penalty(index:int):
if index >= 0: if index >= 0:
while torque_penalties.size() < (index + 1): while torque_penalties.size() < (index + 1):
index-=1 index-=1
if get_rotation().length() != 0:
return torque_penalties[index].rotated(get_rotation().normalized(), get_rotation().length())
else:
return torque_penalties[index] return torque_penalties[index]
return Vector3(0,0,0) return Vector3(0,0,0)
func get_force_penalty(index:int): func get_force_penalty(index:int):
if index >= 0: if index >= 0:
while force_penalties.size() < (index + 1): while force_penalties.size() < (index + 1):
index-=1 index-=1
if get_rotation().length() != 0:
return force_penalties[index].rotated(get_rotation().normalized(), get_rotation().length())
else:
return force_penalties[index] return force_penalties[index]
return Vector3(0,0,0) return Vector3(0,0,0)
Loading…
Cancel
Save