|
extends CharacterBody3D |
|
|
|
const MOVE_SPEED = 12 |
|
const JUMP_FORCE = 30 |
|
const GRAVITY = 0.98 |
|
const MAX_FALL_SPEED = 30 |
|
const TURN_SENS = 2.0 |
|
|
|
@onready var cam = $Camera3D |
|
var move_vec = Vector3() |
|
var y_velo = 0 |
|
var needs_reset = false |
|
# RL related variables |
|
@onready |
|
@onready |
|
@onready |
|
@onready |
|
@onready |
|
@onready |
|
|
|
var |
|
var |
|
var |
|
var |
|
var |
|
var |
|
var |
|
var |
|
var |
|
|
|
|
|
func |
|
ai_controller.init(self) |
|
raycast_sensor.activate() |
|
game_over() |
|
|
|
|
|
func |
|
move_vec |
|
move_vec |
|
move_vec |
|
move_vec.y |
|
set_velocity(move_vec) |
|
set_up_direction(Vector3(0, 1, 0)) |
|
move_and_slide() |
|
|
|
# turning |
|
|
|
var |
|
rotation.y |
|
|
|
grounded |
|
|
|
y_velo |
|
if |
|
robot.set_animation("jump") |
|
y_velo |
|
grounded |
|
if |
|
y_velo |
|
if |
|
y_velo |
|
|
|
if |
|
robot.set_animation("falling") |
|
|
|
var |
|
if |
|
robot.set_animation("idle") |
|
elif |
|
robot.set_animation("walk") |
|
elif |
|
robot.set_animation("run") |
|
|
|
update_reward() |
|
|
|
if |
|
game_over() |
|
|
|
|
|
func |
|
if |
|
return |
|
|
|
if |
|
return |
|
|
|
return |
|
0, |
|
0, |
|
clamp( |
|
( |
|
Input.get_action_strength("move_backwards") |
|
- Input.get_action_strength("move_forwards") |
|
), |
|
-1.0, |
|
0.5 |
|
) |
|
) |
|
|
|
|
|
func |
|
if |
|
return |
|
var |
|
Input.get_action_strength("turn_left") - Input.get_action_strength("turn_right") |
|
) |
|
|
|
return |
|
|
|
|
|
func |
|
if |
|
jump_action |
|
return |
|
|
|
if |
|
return |
|
|
|
return |
|
|
|
|
|
func |
|
next |
|
first_jump_pad.position |
|
second_jump_pad.position |
|
just_reached_end |
|
just_fell_off |
|
jump_action |
|
|
|
set_position(Vector3(0, 5, 0)) |
|
rotation.y |
|
y_velo |
|
reset_best_goal_distance() |
|
ai_controller.reset() |
|
|
|
|
|
func |
|
ai_controller.reward |
|
ai_controller.reward |
|
|
|
|
|
func |
|
var |
|
var |
|
if |
|
goal_distance |
|
if |
|
goal_distance |
|
#print(goal_distance) |
|
if |
|
s_reward |
|
best_goal_distance |
|
|
|
s_reward /= 1.0 |
|
return s_reward |
|
|
|
|
|
func reset_best_goal_distance(): |
|
if next == 0: |
|
best_goal_distance = position.distance_to(first_jump_pad.position) |
|
if next == 1: |
|
best_goal_distance = position.distance_to(second_jump_pad.position) |
|
|
|
|
|
func calculate_translation(other_pad_translation: Vector3) -> Vector3: |
|
var new_translation := Vector3.ZERO |
|
var distance = randf_range(12, 16) |
|
var angle = randf_range(-180, 180) |
|
new_translation.z = other_pad_translation.z + sin(deg_to_rad(angle)) * distance |
|
new_translation.x = other_pad_translation.x + cos(deg_to_rad(angle)) * distance |
|
|
|
return new_translation |
|
|
|
|
|
func _on_First_Pad_Trigger_body_entered(_body): |
|
if next != 0: |
|
return |
|
ai_controller.reward += 100.0 |
|
next = 1 |
|
reset_best_goal_distance() |
|
second_jump_pad.position = calculate_translation(first_jump_pad.position) |
|
|
|
|
|
func _on_Second_Trigger_body_entered(_body): |
|
if next != 1: |
|
return |
|
ai_controller.reward += 100.0 |
|
next = 0 |
|
reset_best_goal_distance() |
|
first_jump_pad.position = calculate_translation(second_jump_pad.position) |
|
|
|
|
|
func _on_ResetTriggerBox_body_entered(_body): |
|
ai_controller.done = true |
|
game_over() |
|
|