Tuesday, January 22, 2019

sprites - Doom-style 2.5D Movement Animations


I've started working on a demo for my 2.5D game. For a basic scene I figured I would just use the good old fashioned doom sprites textured to a double sided plane. Simple enough. But I've been scratching my head as to how to display the proper sprite animation relative to the player viewing the sprite...if that makes since.



For example suppose I have three players in the scene Players A, B, and C as such:


Example layout


Player C should see player A as: Here's an example of what I think player A should look like from C's perspective:


A from C's perspective


While player B would see player A as follows:


A from B's perspective


My current idea is that for any given player, I will need to know the current direction of each other player, and where they are located/moving to relativly. From this, I could calculate which sprite image is required.


Is this correct? What improvements/optimizations could be made?


** EDIT ** Total number of directions will be 8 as depicted below:


enter image description here



For each direction there are two sprites (to show walking movement, sprites for the right hand directions are mirrors of the left):


enter image description here


** EDIT 2 ** Got this working and have a simple javascript/threejs example for anyone interested: https://github.com/commanderZiltoid/threejs-2.5d-fps



Answer



You would need to know the angle to the element from the spectator, so, if you have


A    |
| \aº|
|bº\ |
| \|
| B


where the lines marked with pipes "|" are the "facing" directions, the diagonal is the "attack line", aº is the angle between B sight and A (-30deg) and bº is the angle between A sight and B (-30deg).


You had to add the angles to see the angle of vision (-60deg). that's the rotation of the element, you only have to set the sprite tile that's closer to that rotation angle.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...