You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.0 KiB
144 lines
3.0 KiB
extends MeshInstance
|
|
|
|
class_name Road
|
|
|
|
export var end_rotation:Vector3 = Vector3(0,0,0)
|
|
|
|
export var first_speed_factor:float = 1.0
|
|
export var creator_speed_factor:float = 1.0
|
|
export var chasers_speed_factor:float = 1.0
|
|
|
|
export var reset_index:int = 0
|
|
|
|
export (PoolVector3Array) var speed_constrains = PoolVector3Array()
|
|
export (PoolVector3Array) var force_penalties = PoolVector3Array()
|
|
export (PoolVector3Array) var torque_penalties = PoolVector3Array()
|
|
export (Array,float) var path_penalties = []
|
|
|
|
var body:StaticBody
|
|
|
|
var creator:int = -1
|
|
var preview:bool = false
|
|
|
|
|
|
func _init():
|
|
if not has_node("StaticBody"):
|
|
body = StaticBody.new()
|
|
body.set_name("StaticBody")
|
|
var shape = CollisionShape.new()
|
|
shape.set_name("CollisionShape")
|
|
shape.shape = mesh.create_trimesh_shape()
|
|
body.add_child(shape)
|
|
body.set_collision_layer_bit(0,1)
|
|
body.set_collision_layer_bit(1,1)
|
|
body.set_collision_layer_bit(2,1)
|
|
body.set_collision_layer_bit(3,1)
|
|
add_child(body)
|
|
else:
|
|
body = get_node("StaticBody")
|
|
|
|
|
|
func get_creator():
|
|
return creator
|
|
|
|
|
|
func set_creator(new_creator):
|
|
creator = int(new_creator)
|
|
|
|
|
|
func set_color(new_color):
|
|
pass # TODO
|
|
|
|
|
|
func get_path():
|
|
return get_node("Path")
|
|
|
|
|
|
func get_curve():
|
|
return get_path().get_curve()
|
|
|
|
|
|
func get_lane_curve(lane:int):
|
|
if has_node("lanes"):
|
|
return get_node("lanes").get_child(lane).get_curve()
|
|
else:
|
|
return get_path().get_curve()
|
|
|
|
|
|
func get_end_rotation():
|
|
return end_rotation
|
|
|
|
|
|
func set_preview(prev):
|
|
preview = prev
|
|
if prev:
|
|
set_material_override(SpatialMaterial.new())
|
|
else:
|
|
set_material_override(null)
|
|
|
|
|
|
func is_preview():
|
|
return preview
|
|
|
|
|
|
func get_next_lane(lane):
|
|
return lane
|
|
|
|
|
|
func get_constrain_index(distance:float):
|
|
for index in range(speed_constrains.size()):
|
|
var constrain = speed_constrains[index]
|
|
if constrain.x <= distance && constrain.y >= distance:
|
|
return index
|
|
return -1
|
|
|
|
|
|
func penalty_index(distance:float, speed:float):
|
|
var constrain_index = get_constrain_index(distance)
|
|
if constrain_index >= 0:
|
|
var constrain = speed_constrains[constrain_index]
|
|
if constrain.z < 0 && speed < constrain.z * -1 || constrain.z > 0 && speed > constrain.z:
|
|
return constrain_index
|
|
return -1
|
|
|
|
|
|
func get_torque_penalty(index:int):
|
|
if index >= 0:
|
|
if torque_penalties.size() < (index + 1):
|
|
return get_torque_penalty(index - 1)
|
|
return torque_penalties[index]
|
|
return Vector3(0,0,0)
|
|
|
|
|
|
func get_force_penalty(index:int):
|
|
if index >= 0:
|
|
if force_penalties.size() < (index + 1):
|
|
return get_force_penalty(index - 1)
|
|
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)
|
|
|
|
|
|
func get_path_penalty(index:int):
|
|
if index >= 0:
|
|
if path_penalties.size() < (index + 1):
|
|
return get_path_penalty(index - 1)
|
|
|
|
return path_penalties[index]
|
|
|
|
return 0.0
|
|
|
|
|
|
func get_first_speed_factor():
|
|
return first_speed_factor
|
|
|
|
|
|
func get_creator_speed_factor():
|
|
return creator_speed_factor
|
|
|
|
|
|
func get_chasers_speed_factor():
|
|
return chasers_speed_factor
|