Browse Source

bot improvements

Lurkars 5 years ago
parent
commit
3567fffe88
  1. 4
      project.godot
  2. 1
      scenes/menus/SettingsMenu.tscn
  3. 2
      scenes/road/roadCornerSmall.tscn
  4. 2
      scenes/road/roadCornerSmallFlipped.tscn
  5. 2
      scenes/road/roadRamp.tscn
  6. 4
      scenes/road/roadRampLong.tscn
  7. 2
      scenes/road/roadRampLongCurved.tscn
  8. 2
      scenes/road/roadRampLongFlipped.tscn
  9. 3
      scripts/game/gamestate.gd
  10. 3
      scripts/game/route.gd
  11. 53
      scripts/player/bot_controls.gd
  12. 12
      scripts/road/road.gd

4
project.godot

@ -120,7 +120,7 @@ controls_break={
controls_add_road={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":5,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":4,"pressure":0.0,"pressed":false,"script":null)
]
}
controls_next_road_type={
@ -150,7 +150,7 @@ controls_prev_road_variant={
controls_reset={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":4,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
debug_camera_1={

1
scenes/menus/SettingsMenu.tscn

@ -122,6 +122,7 @@ margin_bottom = 27.0
margin_bottom = 27.0
[node name="action_button" parent="menu/tabs/controls/settings_controls/key_dialog" index="3"]
margin_right = 302.0
margin_bottom = 110.0
[node name="graphics" type="Tabs" parent="menu/tabs"]

2
scenes/road/roadCornerSmall.tscn

@ -11,7 +11,7 @@ material/1 = null
material/2 = null
script = ExtResource( 2 )
end_rotation = Vector3( 0, -1.571, 0 )
speed_constrains = PoolVector3Array( 0.1, 0.79, 0.08 )
speed_constrains = PoolVector3Array( 0.1, 0.6, 0.08 )
force_penalties = PoolVector3Array( 2, 0, 8 )
torque_penalties = PoolVector3Array( 0.1, 0.1, -0.5 )

2
scenes/road/roadCornerSmallFlipped.tscn

@ -11,7 +11,7 @@ material/1 = null
material/2 = null
script = ExtResource( 2 )
end_rotation = Vector3( 0, 1.571, 0 )
speed_constrains = PoolVector3Array( 0.1, 0.79, 0.08 )
speed_constrains = PoolVector3Array( 0.1, 0.6, 0.08 )
force_penalties = PoolVector3Array( 2, 0, 8 )
torque_penalties = PoolVector3Array( 0.1, 0.1, 0.5 )

2
scenes/road/roadRamp.tscn

@ -11,7 +11,7 @@ material/1 = null
material/2 = null
script = ExtResource( 2 )
reset_index = 1
speed_constrains = PoolVector3Array( 0, 1, -0.05 )
speed_constrains = PoolVector3Array( 0.5, 0.9, -0.025 )
path_penalties = [ 1.0 ]
[node name="Path" type="Path" parent="."]

4
scenes/road/roadRampLong.tscn

@ -11,8 +11,10 @@ material/1 = null
material/2 = null
script = ExtResource( 2 )
reset_index = 1
speed_constrains = PoolVector3Array( 0, 2, -0.05 )
speed_constrains = PoolVector3Array( 0.7, 1.9, -0.03 )
path_penalties = [ 2.0 ]
[node name="Path" type="Path" parent="."]
curve = ExtResource( 3 )
[node name="PathFollow" type="PathFollow" parent="Path"]

2
scenes/road/roadRampLongCurved.tscn

@ -11,7 +11,7 @@ material/1 = null
material/2 = null
script = ExtResource( 2 )
reset_index = 1
speed_constrains = PoolVector3Array( 0.25, 1.5, -0.05 )
speed_constrains = PoolVector3Array( 0.7, 1.5, -0.03 )
path_penalties = [ 1.25 ]
[node name="Path" type="Path" parent="."]

2
scenes/road/roadRampLongFlipped.tscn

@ -10,7 +10,7 @@ material/0 = null
material/1 = null
material/2 = null
script = ExtResource( 2 )
speed_constrains = PoolVector3Array( 0, 0.3, 0.12 )
speed_constrains = PoolVector3Array( 0.1, 0.3, 0.12 )
force_penalties = PoolVector3Array( 0, 0, 4 )
[node name="Path" type="Path" parent="."]

3
scripts/game/gamestate.gd

@ -90,7 +90,8 @@ remotesync func prepare_game():
player_scene.set_start(player_scene.get_index())
if bots:
for index in range(MAX_PEERS-players.size()):
# for index in range(MAX_PEERS-players.size()): # DEBUG
for index in range(1):
var bot_index = players.size() + index
var player_scene = Player.instance()
player_scene.set_name("bot_player" + str(bot_index))

3
scripts/game/route.gd

@ -14,7 +14,10 @@ func get_last_road():
func get_road(road_index):
if get_child_count() > road_index:
return get_child(road_index)
else:
return null
remotesync func add_road(type, creator):

53
scripts/player/bot_controls.gd

@ -2,9 +2,13 @@ extends Spatial
var player:Player
const MAX_ROAD_INDEX = 1
var error_rate:float = 0.00
var underspeed_rate:float = 0.00
const MAX_OFFSET = 8.0
const OFFSET_STEPS = 0.01
var break_constrain = 0.0
export var error_rate:float = 0.00
export var underspeed_rate:float = 0.00
func _ready():
@ -18,26 +22,35 @@ func _physics_process(delta):
player.reset()
else:
if player.get_road() != null:
var rate = randf()
var road = player.get_road()
var road_index = 0
var speed_constrain = 0.0
while road != null && road_index < MAX_ROAD_INDEX:
for index in range(road.speed_constrains.size()):
var constrain = road.speed_constrains[index]
if constrain.z > 0:
speed_constrain = max(speed_constrain, constrain.z)
elif constrain.z < 0:
speed_constrain = min(speed_constrain, constrain.z)
road = player.route.get_road(road.get_index() + 1)
road_index += 1
var rate = randf()
var speed = player.current_speed
if speed_constrain < 0:
player.thrust = 1
elif speed_constrain > 0 && speed > speed_constrain:
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.05:
player.thrust = -1
elif rate > underspeed_rate:
elif speed - 0.1 < break_constrain:
player.thrust = 1
elif break_constrain == 0:
player.thrust = 1
else:
player.thrust = 0

12
scripts/road/road.gd

@ -85,15 +85,23 @@ func get_next_lane(lane):
return lane
func penalty_index(distance:float, speed:float):
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:
if constrain.z < 0 && speed < constrain.z * -1 || constrain.z > 0 && speed > constrain.z:
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):

Loading…
Cancel
Save