Mapping entity orientation to direction
Posted: Sun Aug 01, 2021 1:27 pm
Re: https://lua-api.factorio.com/latest/Lua ... rientation
I have long suspected that for entities with arbitrary animation directions (vehicles, turrets, radar) there is not a linear relationship between the RealOrientation of the entity and the animation frame. I have struggled for a long, long time with projectile/beam origin offsets for turrets and finally resorted to rendering and testing like this:
This helped a lot but for scripted effects it still wasn't quite right. It seemed as though the animation frame used was sometimes off.
So I tested it. This is a 64-direction vehicle with a test sprite sheet. The large number here is the animation frame number, the smaller rendered text below is the fraction value that the entity's orientation was set to:
Notice the repetitions and missing numbers. If the relationship was linear then for each frame number N, the number below should be (N-1)/64. But it clearly isn't. You can see this in effect for yourself if you build a custom radar (radars are a weird entity with an orientation that advances per tick instead of being an actual animation) and watch it turning - it clearly speeds up and slows down as it approaches the vertical and horizontal directions.
So what is the formula in the source code for mapping orientation to direction?
I have long suspected that for entities with arbitrary animation directions (vehicles, turrets, radar) there is not a linear relationship between the RealOrientation of the entity and the animation frame. I have struggled for a long, long time with projectile/beam origin offsets for turrets and finally resorted to rendering and testing like this:
This helped a lot but for scripted effects it still wasn't quite right. It seemed as though the animation frame used was sometimes off.
So I tested it. This is a 64-direction vehicle with a test sprite sheet. The large number here is the animation frame number, the smaller rendered text below is the fraction value that the entity's orientation was set to:
Notice the repetitions and missing numbers. If the relationship was linear then for each frame number N, the number below should be (N-1)/64. But it clearly isn't. You can see this in effect for yourself if you build a custom radar (radars are a weird entity with an orientation that advances per tick instead of being an actual animation) and watch it turning - it clearly speeds up and slows down as it approaches the vertical and horizontal directions.
So what is the formula in the source code for mapping orientation to direction?