Facepunch / sbox-issues

175 stars 12 forks source link

Lag compensation fails with hitboxset changes. #3936

Closed andy013 closed 11 months ago

andy013 commented 1 year ago

Describe the bug

I have a model with 2 HitboxSets. One of them contains all of the hitboxes, the other is all of them minus the arms.

If a trace hits the first HitboxSet I wish to swap to the second set to check if the trace would have went through the arms and hit the chest.

The problem is that if you change an entities HitboxSet while using lag compensation then it doesn't position the hitboxes correctly. I think it's using the new HitboxSet but rewinding it to the positions of the old set. I have even seen it position the new hitboxes to where a completely different model was standing.

To Reproduce

  1. Create a model with 2 HitboxSets that are different. (E.g. Citizen model with a second set containing just the head)
  2. Enable lag compensation.
  3. Fire a Trace.Ray with UseHitboxes
  4. If you hit the model change to the second HitboxSet
  5. Do another Trace.Ray immediately
  6. The second trace will not return the correct hitbox or it will be positioned incorrectly. It will work as expected with lag compensation off.

Expected behavior

Swapping the HitboxSet should work with lag compensation.

I can think of 2 potentially different use cases that may need different solutions.

  1. Choose a HitboxSet for the current trace regardless of what set was active when the client sent the command.

This is my current use case where I want the hitbox with the arms to be active all the time but then just do a second trace to check if you hit the chest through them.

  1. Use whatever was the active HitboxSet when the client sent the command.

I can imagine if you wanted the model to transform and change HitboxSet then you would want to rewind to whatever HitboxSet was active for the client at the time that they shot.

Media/Files

No response

Additional context

No response

andy013 commented 1 year ago

Closing for now, I can't reproduce this in a demo project. It must be something else in my code that is causing the problem.

EDIT: The reason my extremely simple demo project couldn't reproduce the issue was because the model only had 1 bone and 2 hitboxes. Even if lag comp used the position of the old hitbox, it would still be correct in this case.

andy013 commented 1 year ago

Here is a little clip showing the behaviour I'm seeing:

https://github.com/sboxgame/issues/assets/10728824/0815fafb-6607-474d-8782-534c34b7acb0

andy013 commented 1 year ago

I tried using the citizen model and I get the same strange results. It seems like a bug to me? Unless I'm doing something stupid.