Public repository for MUR pre alpha
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.
 
 
 
 
 

65 lines
1.7 KiB

extends Spatial
var player:Player
const MAX_OFFSET = 8.0
const OFFSET_STEPS = 0.01
var break_constrain = 0.0
export var overspeed_rate:float = 0.3
export var underspeed_rate:float = 0.1
func _physics_process(delta):
if is_network_master() && player != null:
if player.is_out:
if player.is_resetable:
player.reset()
else:
if player.get_road() != null:
var road = player.get_road()
var rate = util.randf()
var speed = player.current_speed
var offset = 0
var distance = player.follow.get_offset()
var tmp_break_constrain = 0.0
break_constrain = 0.0
while tmp_break_constrain == 0.0 and offset < MAX_OFFSET && road != null:
var constrain_index = road.get_constrain_index(distance)
var road_length = road.get_lane_curve(player.lane).get_baked_length()
if constrain_index >= 0:
tmp_break_constrain = road.speed_constrains[constrain_index].z
if tmp_break_constrain > break_constrain:
break_constrain = tmp_break_constrain
distance += OFFSET_STEPS
offset += OFFSET_STEPS
if distance >= road_length:
distance = 0
road = gamestate.game.route.get_road(road.get_index()+1)
if break_constrain > 0 && speed > break_constrain - 0.04 && rate > overspeed_rate:
player.thrust = -1
elif speed - 0.08 < break_constrain && rate > underspeed_rate:
player.thrust = 1
elif break_constrain == 0 && rate > underspeed_rate:
player.thrust = 1
else:
player.thrust = 0
func set_player(path:String):
player = get_node(path)
get_node("inventory").set_player(player)
func set_overspeed_rate(new_overspeed_rate:float):
overspeed_rate = new_overspeed_rate
func set_underspeed_rate(new_underspeed_rate:float):
underspeed_rate = new_underspeed_rate