Pitch-shift hit sound to hint at damage magnitude
|Status:||In Progress||Start date:||03/16/2012|
Inspired by a hidden setting in QL. Pitch-shifting the hit sound according to damage gives the player an indication of how much damage they have dealt.
A possible issue with this is how to deal with crylink projectiles or grappling hook gravity bombs, which do multiple smaller-damage hits.
As suggested by viddaric on the forum:
#1 Updated by Daan about 2 years ago
I would like to try to tackle this. I spoke about this on IRC with CuBeW0rK_, FruitieX and divVerent. We discussed how to approach the challenge and where in the code the relevant parts can be found. They gave me a clear go, even though it's been officially assigned to tZork. I'm confident I can realize this, and it would be my first contribution to this project.
#6 Updated by Daan about 2 years ago
- File varying_hitsound_v1.diff added
Implemented varying hit sound. It works for spectating players too.
Added cl_hitsound 2 and 3:
seta cl_hitsound 1 "play a hit notifier sound when you have hit an enemy. 0=off, 1=fixed pitch, 2=damage dependent, 3=inversely damage dependent"
Added configuration for varying sound pitch (from defaultXonotic.cfg):
set cl_hitsound_min_pitch 0.5 "lowest pitch of the hit sound"
set cl_hitsound_max_pitch 2 "highest pitch of the hit sound"
set cl_hitsound_nom_damage 80 "damage where pitch of the hit sound is exactly unchanged"
Implementation details: Deprecated STAT_HIT_TIME and added STAT_DAMAGE_DEALT_TOTAL. The server tracks the total damage dealt for each client. The client detects changes to this value and plays sounds accordingly. The server rolls over the counter value when it reaches over DAMAGE_DEALT_TOTAL_ROLLOVER_POINT (500000) to prevent float inaccuracies and overflows. Clients detect and handle a rollover correctly.
I'm in the process of getting write access to the repository. I created a local branch and committed. How do I issue a merge request? I attached the unified diff, should it be useful for something.
#7 Updated by Daan about 2 years ago
The pitch scales from 0 to infinite damage along this curve (default settings). http://www.wolframalpha.com/input/?i=plot+%28b*x*%28a-1%29%2Ba*c*%281-b%29%29%2F%28x*%28a-1%29%2Bc*%281-b%29%29+where+a%3D2+b%3D0.5+c%3D80+x%3D0+to+300+y%3D0+to+3
If the link doesn't work, go to http://www.wolframalpha.com/ and enter "plot (b*x*(a-1)+a*c*(1-b))/(x*(a-1)+c*(1-b)) where a=2 b=0.5 c=80 x=0 to 300 y=0 to 3" without quotes.
The max and min determine the pitch at 0 damage (2 default) and the asymptote (0.5 default) respectively. The 'nominal damage' configures the point at which the pitch shift resolves to 1 (80 default). These values seem to work very well in my own testing.
#9 Updated by Daan about 2 years ago
rafallus, I posted the working code in the diff file above. If you want to experiment, apply the diff to the data branch and compile. It doesn't work online because the server code changed too, but you can try it against bots. Set cl_hitsound to 2 or 3. I'm still awaiting write access to the repository.
- % Done changed from 0 to 50
The idea is nice, but this implementation has a few problems. It's not spectatable reliably, and the hit sound randomly stops working for players.
Also, perhaps damage_dealt_total should be reset to 0 on the server, as networking values up to 5000 may use more bandwidth.