Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I do to make an exact 90 degree turning when make action of turning left/right #279

Closed
TianyuanYu opened this issue Feb 11, 2018 · 7 comments
Labels

Comments

@TianyuanYu
Copy link

Hi, all,

How can I do to make an exact 90 degree turning when make action of turning left/right
How can I do to make a fixed distance move such as 100 when make action of moving forward

Thanks very much

@Miffyli
Copy link
Collaborator

Miffyli commented Feb 11, 2018

Hey,

For turning, you can use TURN_LEFT_RIGHT_DELTA. This specifies amount of turn in degrees per tick, so if you do one action with TURN_LEFT_RIGHT_DELTA = 90 for exactly one tick (i.e. game.make_action(actions,1), you will turn 90 degrees left.

As for moving fixed distance this is bit trickier as player does not just move in constant speed, rather accelerate and reach some maximum speed, and it also takes time to completely stop. You could possibly change actor's properties via ACS scripts, but I do not know proper way for this. If you do not need absolute accuracy, you could keep MOVE_FORWARDing until you have moved wanted distance.

@mwydmuch
Copy link
Member

Hello @TianyuanYu,
as @Miffyli said, Doom's physics makes it a little bit difficult to make a movement that precise.
However, if you want to have a discreet space of moves, ACS scripting language allows you to check keys status, so you can override MOVE_FORWARD and bind it to function that will teleport the player exactly by 100 units. I can make an example for you.

@TianyuanYu
Copy link
Author

TianyuanYu commented Feb 12, 2018

Thanks very much @Miffyli @mwydmuch

I have tried this
`
from vizdoom import *

game = DoomGame()
game.set_doom_scenario_path('my_way_home_notarget.wad')
game.set_doom_map("map01")
game.set_screen_resolution(ScreenResolution.RES_160X120)
game.set_screen_format(ScreenFormat.GRAY8)
game.set_render_hud(False)
game.set_render_crosshair(False)
game.set_render_weapon(False)
game.set_render_decals(False)
game.set_render_particles(False)
game.add_available_button(Button.MOVE_FORWARD)
game.add_available_button(Button.TURN_LEFT)
game.add_available_button(Button.TURN_RIGHT)
game.add_available_button(Button.TURN_LEFT_RIGHT_DELTA)
game.add_available_game_variable(GameVariable.AMMO2)
game.add_available_game_variable(GameVariable.POSITION_X)
game.add_available_game_variable(GameVariable.POSITION_Y)
game.add_available_game_variable(GameVariable.ANGLE)
game.set_episode_timeout(21000000)
game.set_episode_start_time(0)
game.set_window_visible(True)
game.set_sound_enabled(False)
game.set_living_reward(-0.0005)
game.set_mode(Mode.PLAYER)
game.init()
game.new_episode()
while not game.is_episode_finished():
s = game.get_state()
x = s.game_variables[1]
y = s.game_variables[2]
angle = s.game_variables[3]
print 'x' +str(x)
print 'y' + str(y)
print 'angle' + str(angle)
game.make_action([0,1,0,90])
`

Some results I get is

x1043.1000061
y60.2079925537
angle70.5487060711
x1043.1000061
y60.2079925537
angle344.064331135
x1043.1000061
y60.2079925537
angle257.579956115
x1043.1000061
y60.2079925537
angle171.095581095

It is quite similar with 90 degree but not. Is that the right way to use TURN_LEFT_RIGHT_DELTA?
The most weird thing is that the agent actually turns right if I use sleep to watch how it turns!!!
I will appreciate it if you can make an example.

Thank you very much!!!

@Miffyli
Copy link
Collaborator

Miffyli commented Feb 12, 2018

@TianyuanYu

You are using TURN_LEFT_RIGHT_DELTA and TURN_LEFT at the same time. You do not need to use TURN_LEFT/RIGHT buttons if you use TURN_LEFT_RIGHT_DELTA. Try game.make_action([0,0,0,90]) instead. Other than that things seem correct. As for which way agent turns: I cannot recall precisely which way the agent turns with positive speed, but norm is that positive turn is anti-clockwise (i.e. left in player's point-of-view).

Offtopic: You can use game.get_game_variable(GameVariable.POSITION_X) etc to also read variables. Makes slightly more readable code :)

@TianyuanYu
Copy link
Author

Thanks very much @Miffyli
Really helpful!

@mwydmuch
Copy link
Member

Added this issue to a new FAQ.md file.

@ankitkv
Copy link

ankitkv commented Oct 30, 2018

@mwydmuch Had you written the example for moving forward by a fixed number of units?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants