Feature #1128

Pitch-shift hit sound to hint at damage magnitude

Added by MrBougo over 2 years ago. Updated 2 months ago.

Status:In ProgressStart date:03/16/2012
Priority:LowDue date:
Assignee:Samual% Done:


Target version:0.8


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:

varying_hitsound_v1.diff Magnifier - unified diff to xonotic-data.pk3dir (15 KB) Daan, 06/27/2012 12:50 am


#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.

#2 Updated by MrBougo about 2 years ago

I can't assign the feature item to you, but go ahead! Make sure to get access to git and work with that from the beginning.

#3 Updated by tZork about 2 years ago

Go for it Daan. I haven't the time for it any time soon anyway, so you offering up is much appreciated =)How to sort the accrual merge and ticket assignments can be sorted later.

#4 Updated by Daan about 2 years ago

Alright, thanks guys. I'm on it.

#5 Updated by tZork about 2 years ago

  • Assignee changed from tZork to Daan

#6 Updated by Daan about 2 years ago

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.

#8 Updated by rafallus about 2 years ago

Any updates on this? I'm pretty eager to test it in action, and surely I'm not the only one who wants to do so.

#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.

#10 Updated by Samual over 1 year ago

  • Category changed from Game Logic to Sounds
  • Status changed from New to In Progress
  • Assignee changed from Daan to Samual
  • Priority changed from Normal to Low
  • Target version set to 0.8

#11 Updated by Mario 2 months ago

  • % 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.

Also available in: Atom PDF