hh79 / gzdoomvr

Classic Doom/Heretic/Hexen games in stereo 3D and VR; modified version of gzdoom.
GNU General Public License v3.0
125 stars 10 forks source link

Shotgun and other weapon projectile spread is a flat line #27

Closed DrBeef closed 4 years ago

DrBeef commented 4 years ago

Hi, I must admit, I've not tried it myself, but our mutual friend Ajantaju tells me that this version suffers from the same issue that QuestZDoom had, whereby the projectiles from a multi-projectile weapon, such as shotgun or repeated shots from a chaingun are all flat in spread (there's no random pitch applied).

I have come up with a solution, it's not perfect, but it gets the job done, figured you would be interested in seeing it.

In p_mobj.cpp, in the function, P_SpawnPlayerMissile, where the source->player->mo->OverrideAttackPosDir is used to override the aim with the orientation of the controller, I changed the calculation of pitch to the following (I have retained the comment here so you can see why I did it this way):

        //
        //  FIX FOR FLAT PROJECTILE SPREAD FROM SHOTGUNS AND OTHER MULTI-PROJECTILE WEAPONS
        //
        //Bit of a hack as it makes the pitch a little off, but in order for weapon projectile spread
        //to work correctly, we can't fix the pitch to that of the controller otherwise random spread
        //turns into a flat line of projectiles. Using the difference between the previous known angles and
        //the current angles (which were potenitally modified by A_FireProjectile) gives us the "random"
        //difference applied to the pitch by the script
        //
        //A VR player is unlikely to be whipping their head up and down so fast as to make a meaningful
        //difference to the pitch between two frames, so this is 'good enough' for now.
        pitch = dir.Pitch() + (source->PrevAngles.Pitch - source->Angles.Pitch);

I hope that helps (assuming you do indeed have this same issue)

SinaelDOverom commented 4 years ago

There's a bunch of other ZScript, Decorate and ACS functions that disregard the Y-coordinate entirely when it comes to supposed screen-space.

hh79 commented 4 years ago

Thanks, but frankly I don't fully understand the problem. When I am playing in no VR mode shots from a shutgun seem to be also in a straight line. I can not see much a difference on walls. The holes look more or less the same in no VR and VR modes.

Anyway, the fix, seems to work as the holes on walls are now more diagonal.

DrBeef commented 4 years ago

Curious.. I was originally testing with the Meatgrinder mod, which the fix I have given you will resolve, however if you are playing with Brutal Doom, it requires a different fix (which I discovered last night). The difference is very pronounced. However I don't understand how it could be working fine in non-vr mode, since this is an issue caused specifically by the use of overriding the pitch based on controller orientation, which is removing the "random scatter" element of various projectiles (hence them all appearing in a line). I'll post the other part of the fix here, if I get a chance I will post a short clip of the difference between a shotgun with and without the fix.. it is very obvious.

SinaelDOverom commented 4 years ago

Thanks, but frankly I don't fully understand the problem. When I am playing in no VR mode shots from a shutgun seem to be also in a straight line. I can not see much a difference on walls. The holes look more or less the same in no VR and VR modes.

Anyway, the fix, seems to work as the holes on walls are now more diagonal.

Original Shotgun was always a straight line. But supershotgun was not. You can test with that. Also here's a DAKKA mod which shotguns and chaingun also demonstrate the issues quite obviously: http://git.jinotra.in/ijon/dakka Basically anything that comes from player and has a vertical angle has said vertical angle removed.

DrBeef commented 4 years ago

Here's a couple of comparison videos so you can see the difference. In this example I am using the Brutal Doom double barrelled shotgun. However it is the same for any weapon where the script tries to apply a random pitch element to the bullet spread.

This is what you see in the unfixed version:

https://youtu.be/HowZVqa8MsY

And this is an example from when the fixes are applied ( this is from QuestZDoom ):

https://youtu.be/Z93E_ylYXQs

I'll try to summarise the changes required, it is a bit more required than the original change I suggested unfortunately.

hh79 commented 4 years ago

Thanks, now I am seeing the difference. I tried to merge your changes but I stumbled on code which you added in SetUp method

player->mo->AttackPitch = -weaponangles[PITCH];
player->mo->AttackAngle = -90 + (doomYaw - hmdorientation[YAW]) + weaponangles[YAW];

Is it just orientation of the weapon controller ?

DrBeef commented 4 years ago

I think it might be easier if I fork and make the changes in your branch (as I don't think you need to take on some of the changes like those above, I expect you can get away with a minimal number) so that you only get the bits required to resolve the issue. I'll then submit a pull request with the changes and you can merge (and fix any build issues, shouldn't be any, but I won't be able to build your code, so I will keep the necessary changes to an absolute minimum).

Does that sound ok?, otherwise I might be coaching you through changing great chunks of this port that don't need to change as they work perfectly well already.

Let me know what you think.

hh79 commented 4 years ago

Yes please, if you could make a PR it would be great.

DrBeef commented 4 years ago

I've got the changes committed to my own fork, but want to double check my changes (I'll test them in QuestZDoom, as they are the same) and do some more testing before I submit. Should be ready in a day or two..

hh79 commented 4 years ago

Thank you, I really appreciete your help with this.

DrBeef commented 4 years ago

I've created the PR. I'll let you close this issue if you are happy with the results :)

hh79 commented 4 years ago

I tried to merge it but there is one issue. I put a commentary in PR. Anyway it seems its working, will be in the next release. Once again thanks for help.

DrBeef commented 4 years ago

No problem, as I mentioned on the PR, it will be fine without the AttackPitch and AttackAngle bits of the change. As it seems to be working and is in the next release I'll close this issue for you :)