Thanks.
The rotations part is actually being done in C++. Each animation is composed of 8 flipbooks, one for each angle. You can have more or less, depending of how “smooth” you want the transition to look, 8 is what DOOM and Duke Nukem 3D used and I think it looks good enough.
Now, for the code itself. On every Tick the sprite is being rotated towards the camera around the Z axis, the tricky part is that each sprite now has 2 rotations: one 3D rotation, the one used in the plane where the sprite is being drawn and the rotation of the enemy/item itself. That second one is maintained by code and is the one used to check if the enemy is facing the player and things like that.
To decide what flipbook should be used, I get the yaw from the difference vector between the camera position and the actor and use that angle to decide which animation should be used there:
float offset = (360.0 / Animations.Num());
if (angle < 0)
angle += 360.0;
if (angle > 360.0)
angle -= 360.0;
angle -= SpriteYaw; //Actual Yaw of our 2D actor
angle += offset/2;
if (angle < 0)
angle += 360.0;
if (angle > 360.0)
angle -= 360.0;
int index = (int)FMath::Abs(floorf(angle / offset));
if (index >= Animations.Num()) index = 0;
return Animations[index];
I hope that is clear enough…