Review possible incorrect behavior of hero's movement angle in different scenarios
Reproducing this behavior
This has been tested in Solarus 1.6.4 in a very simple way:
- Creating a new quest from File -> New quest
- Adding the file scripts/hero/on_movement_changed.lua with the following content:
local hero_meta = sol.main.get_metatable("hero")
function hero_meta:on_movement_changed(movement)
print("movement changed")
local hero_angle = movement:get_angle()
print("hero angle: " .. hero_angle * 180 / math.pi)
end
- Editing features.lua to require the file.
It just prints the angle of the hero's movement each time the movement changes
Scenario 1
Behavior
After walking in any of the 4 main directions, the angle is at some point always set to 90 degrees. I find it a bit strange that is 90 and not other value
Expected behavior
While I walk in a specific direction the angle remains constant
Scenario 2
Behavior
Moving in 8 directions, besides the 8 possible expected angles I get some other values, with decimals.
Expected behavior
I would expect to always see angles: 0, 45, 90, 135, 180, 225, 270, 315
Scenario 3
Behavior
If I am looking to a direction different than 0, with the hero stopped (and an angle different than 0) I use the sword and after that the angle changes to 0. This happens after any state change of the hero. For example I implemented a custom state for jumping, before the jump maybe the angle is 180, as soon as the jump is triggered (even if the hero doesn't move at all) the angle changes to 0.
Expected behavior
I would expect that the angle, even when stopped, would be the latest angle that the movement had before it was stopped. So if the hero was walking left (180 degrees) and stops the movement's angle will be 180 (this is working) and now if the hero swings the sword while staying in the same position I would expect that the hero's movement angle would stay in 180 degrees. Comment from Christopho on this: "I think the angle when stopped should be whatever was set by the latest set_angle() call, for consistency. Unless the engine internally does an additional set_angle(math.pi) call when stopped, for some reason"