edbeeching / godot_rl_agents_examples

Example Environments for the Godot RL Agents library
MIT License
37 stars 13 forks source link

Jumper Hard example may have an error with goal vector. #25

Closed edbeeching closed 6 months ago

edbeeching commented 6 months ago

Hey @metinc , I was wondering what you think about this line in the examples refactor. https://github.com/edbeeching/godot_rl_agents_examples/blob/72e4825651f1c9b078c3e7861b56267f78d0b0d6/examples/JumperHard/AIController3D.gd#L25

I think this should be:

goal_vector = goal_vector.rotated(Vector3.UP, -_player.rotation.y)

What do you think?

metinc commented 6 months ago

You are right. The AiController3D is a child of the player and -rotation.y will always be 0. But I was thinking if we could simplify this code a bit by using the global position of the goal and making it local to the player. Would something like this work?

var goal_vector = Vector3.ZERO
if _player.next == 0:
    goal_distance = _player.position.distance_to(_player.first_jump_pad.position)
    goal_vector = _player.first_jump_pad.global_position

if _player.next == 1:
    goal_distance = _player.position.distance_to(_player.second_jump_pad.position)
    goal_vector = _player.second_jump_pad.global_position

goal_vector = _player.to_local(goal_vector).normalized()

Maybe this would make the code easier to read.

edbeeching commented 6 months ago

Sounds good, I made a PR #26 if you can review.

edbeeching commented 6 months ago

fixed in #26