[TF2] Fixed Beach Ball going Invisible when shot at#1721
Conversation
This patch fixes the beach ball/Smissmas ornament ball from going invisible by preventing invalid numbers from being used in the math. If invalid numbers are used (for example 0) it catches it and changes it to 1
| boingSide.NormalizeInPlace(); | ||
|
|
||
|
|
||
| if (data->boingDir.IsZero()) data->boingDir = Vector(0, 0, 1); |
There was a problem hiding this comment.
This is a poor way of fixing it, the source of this issue comes from the normalization of the velocity up above, which returns a non-zero result even if the velocity is zero, and it fails the epsilon check as it happens to be bigger than 0.00001f
Higher up on line 591, this will fix it properly:
float speed;
if ( vel.IsZero() )
{
vel = Vector( 0, 0, 1.0f );
speed = 0.0f;
}
else
{
speed = vel.NormalizeInPlace();
speed /= deltaT;
}There was a problem hiding this comment.
This is an great improvement.
Looking at the Intel platform code, given vel as the zero-vector, NormalizeInPlace looks to theoretically return exactly 0.00001 (the inverse square root of 1.0e-10f (100 000) multiplied by 1.0e-10f).
The result is obviously not less than 0.00001.
Checking early for the zero vector in NormalizeInPlace, and returning 0.0f is better for this specific case, but will just slow things down in every other case.
Included Ficool's better fix
|
Someone has already uploaded a fixed model for the ball that handles this the (probably) correct way, by adding a base bone on the model for which the jigglebone can jiggle relative to; see ValveSoftware/Source-1-Games#4208 (comment) Does this change allow for better handling of jigglebones in general? If not, this probably does not need to go through, in favor of fixing the model itself. Also should probably revert the whitespace changes. |
This is likely to fix other assets other than the ball, therefore this PR is still relevant, besides theres clearly a bug in the code as the check for invalid inputs is not correct |
This is incorrect. I've tested the fix you linked before (which is what led me to actually investigating what caused the bug in the first place) For example the hat "A Rather Festive Tree" also uses the is_boing property. Turning it into a physics prop and shooting it also turns the jigglebones (The ones that use the is_Boing property) from that hat invisible in base TF2. The PR fixes that. Before.is_Boing.Fix.mp4After.is_Boing.Fix.mp4 |
That's odd; why does the model fix work in that case, then? Why does adding the base bone somehow resolve the issue for that particular model? Is it related to skipping some broken logic here if another bone is present? Would be useful to know why exactly that workaround works even if it's not the 'correct' way to fix it. Also it's looking like the ball model should get that base bone anyways in addition to this PR fix, just as a 'correctness' measure, since it seems like without a base bone if another bug crops up with jigglebones this can happen again (based on your video of the Xmas hat folding in on itself instead of outright disappearing, since it has the base bone).
Agreed that this PR should go through then. |
|
Let this PR slide |
|
EDIT: I've been testing this in-game today and it seems I've been wrong about the cause of this issue all these years. I assumed it was related to network settings, but upon further inspection I realized that once I set my interpolation to 0.1 and back, the ball would continue to not disappear. Which shouldn't be the case, obviously. I think I've found the actual cause of it and hence the confusion on my end: Changing my network settings causes my game to stutter shortly, enough for it to recognize my framerate has dipped below 20 fps which is also the the default for cl_jiggle_bone_framerate_cutoff. Interestingly, this will cause the ball to stay visible for the entire game even if your framerate stays high. Although, I hadn't realized it also causes the jiggle to look, uh, a little broken when you look more closely. So I guess back in 2011 or so when I changed my network settings to default and realized the ball would stay visible it was a case of false correlation. I can't believe I've been mistaken about this for all these years. I apologize for the confusion. I now assume people who've never seen the ball go invisible have a lot more unstable framerates that frequently dip below 20, have a different cut-off value or they disabled jigglebones entirely for whatever reason.
Hey, I just watched the video. This bug is as old as 2011 at least because this has always been an issue for me. You should also know that setting your network settings back to default fixes it, too. So if you have cl_interp 0.1, the ball will work fine even without this fix. I'm not a programmer either, I don't really understand what you guys changed, but network settings have always been the culprit for me. I just accepted these minor issues for lower interpolation. The ball isn't the only thing affected by cl_interp being different from 0.1. It also causes Sentries and NPC bosses to animate at low framerates. |
| float speed; | ||
| if ( vel.IsZero() ) |
There was a problem hiding this comment.
Not to be rude at all, just because the author is not a developer, I would recommend to "suggest" changes directly on the comment, so the author only has to "accept" the change and that's it! Github has the suggestion usage on the markdown code and comment formatting section, and it is awesome!
| float speed; | |
| if ( vel.IsZero() ) | |
| float speed; | |
| if ( vel.IsZero() ) |
| } | ||
| boingSide.NormalizeInPlace(); | ||
|
|
||
There was a problem hiding this comment.
Remove the whitespace/unrelated change
|
I have a sneaking suspicion that the culprit is the float speed = vel.NormalizeInPlace();
if ( speed < 0.00001f ) <------------ This line
{
vel = Vector( 0, 0, 1.0f );
speed = 0.0f;
}
else
{
speed /= deltaT;
}Has anyone tried simply removing the float speed = vel.NormalizeInPlace();
speed /= deltaT;This theory would also explain why @ficool2’s suggested fix works. My guess is that the change from EDIT: After testing I've come to the conclusion that my theory is wrong. I also realized that |
|
Just saying this as a heads up. This pull request made it onto Hackaday news, so it might get a lot more attention soon. |


This patch fixes the beach ball/Smissmas ornament ball from going invisible by preventing invalid numbers from being used in the math. If invalid numbers are used (for example 0) it catches it and changes it to 1
To note: While this issue could technically be fixed by preventing the Ball from using the is_boing property, it would also remove the jiggle effect when interacting with the world. My fix preserves both the visibility of the ball when shot as well as the jiggle effect included in the model's QC
Before
before.fix.mp4
After
after.fix.mp4