- Joined
- Feb 14, 2016
- Messages
- 5
- Reaction score
- 2
- First Language
- Russian
- Primarily Uses
Good time of day to you all!
Basically, what I'm looking for is a script that will "rotate" my character before moving. By "rotate" I mean that if, for example, the player is facing up and I move down, I want my character to first turn top-right, right, bottom-right, and only then down.
So the algorithm I need is as follows:
if pressed button once ->
set_direction(top-right)
wait
set_direction(right)
wait
set_direction(bottom-right)
wait
set_direction(down)
if keep pressing button ->
move
I've been struggling with this for a few days now, and the only solution I came up with, involves a counter. Here is a small fragment:
case Input.dir8
...
when 0, 5
@turn_flag = 0
when 1 # down
...
if @prev_direction == 9 # up
if @turn_flag == 0 then set_direction(7) end
if @turn_flag == 3 then set_direction(2) end
if @turn_flag > 6
set_direction(Input.dir8)
move_diagonal(6, 2)
@prev_direction = Input.dir8
end
end
...
@turn_flag += 1
end
The problem with this solution is that if I release the button before the counter ticks to 6 (like in the example above), the character will not fully rotate in the desirable direction.
I've tried using wait functions based on Fiber.yield loops but they are not working properly.
Basically, what I'm looking for is a script that will "rotate" my character before moving. By "rotate" I mean that if, for example, the player is facing up and I move down, I want my character to first turn top-right, right, bottom-right, and only then down.
So the algorithm I need is as follows:
if pressed button once ->
set_direction(top-right)
wait
set_direction(right)
wait
set_direction(bottom-right)
wait
set_direction(down)
if keep pressing button ->
move
I've been struggling with this for a few days now, and the only solution I came up with, involves a counter. Here is a small fragment:
case Input.dir8
...
when 0, 5
@turn_flag = 0
when 1 # down
...
if @prev_direction == 9 # up
if @turn_flag == 0 then set_direction(7) end
if @turn_flag == 3 then set_direction(2) end
if @turn_flag > 6
set_direction(Input.dir8)
move_diagonal(6, 2)
@prev_direction = Input.dir8
end
end
...
@turn_flag += 1
end
The problem with this solution is that if I release the button before the counter ticks to 6 (like in the example above), the character will not fully rotate in the desirable direction.
I've tried using wait functions based on Fiber.yield loops but they are not working properly.

