Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Precise collision for 3D models and sprites #1300

Closed
Username-N00b-is-not-available opened this issue Apr 25, 2023 · 12 comments
Closed
Assignees
Labels

Comments

@Username-N00b-is-not-available
Copy link
Contributor

Username-N00b-is-not-available commented Apr 25, 2023

Now that we have around 50% less issues than a month ago, it's again time for some new features :-)

I have recently (March and April) written some code for precise collision on:

  • 3D models. This could be useful for calculating effective armor on tanks and making tank fights more realistic, e. g. to destroy a Tiger you'll have to flank it or aim carefully at its weakpoints. See https://youtu.be/6DzjJ2OMnMc ("probilo"/"ne probilo" written to console means "has penetrated"/"has not penetrated" in transliterated Russian, the left number is the steel thickness that the shell would penetrate, the right is derived armor thickness).
  • Sprites. You can now hit separate parts of a sprite for different outcomes. This is general purpose, useful for close combat, sniping and so on. https://youtu.be/xUBbw4rehxE

The bullets won't anymore score a hit when they hit the Doom hitbox but miss the enemy sprite or model. You can snipe enemy heads, shoot their arms for lowered damage or even miss an enemy and hit someone behind him.
Collisions are calculated for pointwise bullets/tank shells; in models, for hitscan imitations of FastProjectiles (these are used so very high speed projectiles do not become a performance drain), and in sprites, for (almost stock) BoA bullets. The code can be easily converted to either type.
I would rather not wager all of this is completely bug-free for now, but both cases seem to work well during my tests, and I would like to ask the team members @Tormentor667 @Ozymandias81 @Talon1024 for opinions.


Should I try to do the following to the base game:

  1. Add proper 3D hitbox models of tanks with historical armor values and change the player tank system to add multiple shell types?
  2. Add code and 'hitmaps' for damage zones on sprite enemies, starting with the most common ones?
  3. Change (all) BoA FastProjectile bullets into hitscan imitations, for performance reasons?

3 would be easy.
For 1 I already have a few tank hitboxes and a testmap (if anyone is interested, I can share it), it is built upon BoA tank code but with heavy modifications.
For 2 we need the hitmaps, which will be a huge task, however I have already done it manually for the Afrika Korps guard (around 80 sprites), and won't have to do other soldiers from scratch; I also have a demo.

I'll do any of these in a separate branch so we won't have to revert the master. Then, if the results are fine, you'll merge it.

@Tormentor667
Copy link
Contributor

This is impressive, I wasn't aware that GZDoom can do that. I really like the possibility though and I'd be happy to have it part of BoA - especially when damage dealt to the head is stronger. I see a lot of fun happening with the sniper then.

Regarding the hitmaps: Can you share how they are looking like?

@Username-N00b-is-not-available
Copy link
Contributor Author

Username-N00b-is-not-available commented Apr 25, 2023

The 'hitmap' is just a companion sprite that is based on the actual one.
GARDC2_0 GARDC2_1
The hitmap should have the same dimensions and offsets, but it should be a Doom format paletted image (PNG, BMP or any other formats will not work). The palette used is a special one, with large distances between consecutive colours (so you won't confuse them in an editor). A single colour corresponds to a logical 'zone' on the sprite, e. g. above:

  • red is 'stomach' (normal damage),
  • blue is 'legs' (0.5x damage, reduces walking speed 2x),
  • magenta is 'arms' (0.5x damage),
  • cyan is 'chest' (1.5x damage),
  • yellow is 'head' (instant death),
  • cream is 'helmet' (0.5x damage for pistol bullets and shotgun pellets, but instant death for rifle bullets), and so on.

You can define 255 different zones. If that is not enough, same zones on different actor types might be used for different effects.


I think the drawing process might be (at least partially) automated, especially for soldier enemies, though I don't have experience in this.

@Username-N00b-is-not-available
Copy link
Contributor Author

Username-N00b-is-not-available commented Apr 26, 2023

Here is an example regarding point 2 (for BoA, but the map has Doom II textures I did not bother to change): spritetracerv2.zip


Warp to MAP01 slot, then high-five one of the imps to open the door (by pressing 'use'). If you slap him in the face instead, you'll be punished. Note that there are some +FLATSPRITE +ROLLSPRITE imps and some normal ones, angle, scale and roll are also accounted for.

Then notarget, idfa, summon wguard (or guard) and shoot the guard (or multiple ones) using either a Luger or a Kar98k.


Does not currently work well with soldiers (and ProjectileRay) from a different elevation or from a point-blank range; for imps and PlayerRay everything seems to be fine.

@Username-N00b-is-not-available
Copy link
Contributor Author

Username-N00b-is-not-available commented Apr 28, 2023

The hitscan-3D model collision code for tanks seems too contrived, I was not able (at least yet) to backport these changes into BoA without bugs. This has to do with e. g. pixelstretch which was 1.0 on my testmap and 1.2 in BoA (inherited from Doom). So point 1 is deferred to an unspecified time in the future, looks like I'll have to rewrite it from scratch.
This leaves points 2 and 3. For 2 the main problem would be writing a script which would be able to detect the soldiers' arms on the sprite to generate a meaningful hitmap...

I have a working example, but it is not built on BoA and cannot be modified easily.

@Username-N00b-is-not-available
Copy link
Contributor Author

Well ackchyually I've managed to do 1. If anyone @Tormentor667 @Talon1024 @Ozymandias81 wants to check it out in BoA, it is in the branch modelcollision, I've added there a testmap TEST_TNK specifically for tank battles.


I also decided I'd rather post my non-BoA example here. Yesterday I had failed because I wanted to incorporate every feature from this example at once.
There are two files, you should launch the pk3 one and choose the ipk3 as an IWAD (+ DOOM2.WAD will load automatically as a PWAD, it is also necessary) --- I just wanted to add new keybinds specifically for this example that would not interfere with the default ones.
There is a single map (MAP01), outskirts of a huge factory that is being defended by enemy PzIV's and T-34/85's; you need to take them out with your tank and enter the factory.
New controls (when you are in a tank):

  • 1, 2, 3: change tank shell types. They have different speeds, damage and penetration values.
  • mouse wheel: enter sniper mode or zoom in/out (up to 25x).
  • right mouse button: fix/unfix the current turret and cannon position.

Features:

  • Derived armor calculation. If the plate is too thick, the shell will not penetrate and will not deal any damage (in the BoA version it will deal only a little fraction of its base damage). If the shell hits the armor plate from an oblique angle, it is much less likely to penetrate.
  • Precise crosshair calculation in sniper mode (it accounts for player's movement).
  • The red numbers over tanks are current health values.

As it is just a testing example, you can shoot way faster than the enemies. Please note that the damage will only be dealt if you shoot the hull or the turret (as the crewmen and the most important modules are there), and most of the details (like the gun, tracks, or fuel tanks, which are supposed to be empty during battle) are removed from the collision models!


The models that are used in the calculations have around 200 triangles each, and the hitscan-model intersection algorithm is currently brute-force. If it becomes a performance problem, an octree generator would be easy to integrate here, but it would have to be written first :-) (I have never done it myself yet).

@Username-N00b-is-not-available
Copy link
Contributor Author

Did anyone by chance have time to test the examples (two in the posts of this issue and one in a separate repository branch)? I am not going to do radical changes of this sort to master behind the team's back.

@Tormentor667
Copy link
Contributor

Here is an example regarding point 2 (for BoA, but the map has Doom II textures I did not bother to change): spritetracerv2.zip

Finally time for some answers. I tried it and I have to admit that I like it a lot and would like to see it at least for regular human guards incorporated. Would be nice to have but I have no idea how much work is involved and who could actually do it. On the other hand, we should also ask: How much will it impact gameplay? And is it worth the effort in the end?

What do others think @Ozymandias81 @Talon1024 @AFADoomer @DoomJedi ?

(will comment the rest later, just need to pick up my girlfriend from the train now)

@Tormentor667
Copy link
Contributor

Well ackchyually I've managed to do 1. If anyone @Tormentor667 @Talon1024 @Ozymandias81 wants to check it out in BoA, it is in the branch modelcollision, I've added there a testmap TEST_TNK specifically for tank battles.

Could you be so kind and share me a download file? I am not very used to branches so I do not know how to make it on my own the best way.

@Username-N00b-is-not-available
Copy link
Contributor Author

@Tormentor667 Eh, with my internet connection an upload of 700MB will take a few hours...
Are you using GitHub Desktop? If yes, then checking out a branch can be done in the following way:


  1. Make sure you do not have your own unsaved work on the repository.
  2. Fetch the origin:
    image
  3. Press on "Current branch", then choose my tank branch modelcollision and wait a few seconds while git changes your local repository to the state of the branch:
    image
  4. Build the game using the batch file (you know how).

After doing this, you can return to the master branch using the same procedure.

@Username-N00b-is-not-available
Copy link
Contributor Author

Here is a link to the version that was built from the branch: https://drive.google.com/file/d/1a9WqaZTXfMNqFTHBoQILYi8hoWlopRp8/view?usp=sharing
@Tormentor667 I've also sent you an email.

@Tormentor667
Copy link
Contributor

Thank you, just got home from my vacation, will check things out next week :)

@Username-N00b-is-not-available
Copy link
Contributor Author

@Tormentor667 decided that the tank concept is not suitable for BoA, and I have not yet started work on an hitmap generator, so I'll have to confine these features to my mod (if it ever gets done) :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants