Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick and dirty linear interpolation #135

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Conversation

PeeblyWeeb
Copy link

i have no clue what im doing, but it looked like it worked!

@RedFlames
Copy link
Collaborator

RedFlames commented Apr 24, 2024

Hi!

I have some questions about this:

  • I'm curious what made you want to implement this? I guess smoothing out "laggy" Ghosts?...
  • why is it a Debug setting?
  • how does this behave with very fast moving players? What does it look like if I stand across the room or on the opposite end of FW and teleport to you?
  • I don't know how quickly the lerp converges on the target position, but if any of the above look funky, there should probably be a cutoff distance threshold that skips the interpolation
  • does this at all affect other mods like Madhunt, A Friendly Climb, etc.?
  • what does the lerp factor look like?
    I always have a hard time visualizing at what rate this kind of lerp might converge or lag behind. I had to look up Monocle's RawDeltaTime, it looks to be the TotalSeconds of the elapsedGameTime that XNA passes into the game's Update.
    It's a fraction of a second divided up by the framerate.
    So if LerpSpeed < fps, the factor is < 1.0 and scales with the frame time. Lower fps, bigger factor.
    If LerpSpeed >= fps, then factor >= 1.0 so return TargetPosition right away.
    So any LerpSpeed > 60 means lerp is effectively off. At least from my reading, I've yet to play with this. :)
    Should the relationship to gameTime possibly be inverse? Edit: I answered this myself, effectively if FPS drop below the "speed" value, it also skips lerp. So that seems reasonable.
    And, should it matter at all how much time actually elapsed since the last update was received? I suppose as it stands, that's the case just because of Update calls happening, so perhaps that's of no concern.

Just some initial thoughts.

@PeeblyWeeb
Copy link
Author

what made you want to implement this?: yeah, just choppy ghosts and for fun.

why is it a Debug setting?: idk honestly, just had it there for well debugging purposes so i could change it in-game i personally think its useful to keep.

how does this behave with very fast moving players?: i've made a commit since this question that should fix the player interpolating to you on teleport (if the player has no velocity, don't interpolate if their position changed)

does this at all affect other mods like Madhunt, A Friendly Climb, etc.?: gone ahead and tested these and they seem to work fine, keep it mind this was tested on 270ms because the other person lives a ways away from me.

what does the lerp factor look like?: i've changed it to interpolate based on an update rate across a start and end position, update rate configurable in debug settings, defaults to 30 which is 0.03 seconds of interpolation.

..also added client prediction, feel free to review that. (togglable under in-game settings)

Dialog/English.txt Outdated Show resolved Hide resolved
Co-authored-by: ThatOtherAndrew <[email protected]>
@PeeblyWeeb
Copy link
Author

PeeblyWeeb commented Apr 24, 2024

  • does this at all affect other mods like Madhunt, A Friendly Climb, etc.?

also wanna thank you for bringing these maps to my attention, had a lot of fun with "A Friendly Climb"!
image

@Brokemia
Copy link

Brokemia commented Apr 30, 2024

if the player has no velocity, don't interpolate if their position changed

Have you tested what happens with something that teleports you while you might be moving? For example, the Outback Helper portals

@ghost
Copy link

ghost commented May 1, 2024

say it was to occur it would interpolate from where the portal was triggered to where the portal teleports you over 1/playerUpdateRate (1/20th of a second, 0.05 seconds), i dont really think its an issue

@RedFlames
Copy link
Collaborator

interpolating to 20 frames seems quite bad especially as a proposed default.

I think this would look weird even just on someone doing an ultra or possibly even just wavedashes. I think this idea is nice in theory but quickly falls apart with the silly amounts of speeds and direction changes players can do in very few frames, even when not Thinking With Portals.

https://www.youtube.com/watch?v=JpT-rEpQQr8

I just recorded a little comparison with this PR, recorded at 60 fps and then played back slowly in VLC (not the most scientific method)
But you can very clearly see the difference. Yeah, the no-interpolation ghosts are choppy. And the interpolated ones less so.
But even when I had it at rate 40 (not shown in the clip) the rubber-banding was still visible between the portals.

Also, check top left corner at ~00:47s I'm pretty sure just from the hyper's speed Tim gets over-predicted into the wall.

There probably needs to be
(a.) a distance limit in a relatively tight circle around players for where anything moving outside will snap normally like a teleport (due to lag, ludicrous speed, or portals etc.)
(b.) maybe also a speed limit in general for when interpolation gives up or gets dialed down a lot?

@ghost
Copy link

ghost commented May 1, 2024

the default 20 is meant to be enabled with client prediction, so you could make it an in-game option instead of a debug option.
at 47s he does get predicted into a wall for somewhere around 100 to 150ms which is an issue but with general gameplay its not really an issue since it gets corrected in such a sort amount of time
(a.) this is a sort of bandaid solution because if the portals where within that "distance limit" then interpolation would occur, or if the distance value is too low then doing a wavedash would cause jittering/teleporting.
(b.) dont get the issue with speed because at high speeds the only issue is with client prediction predicting you through walls which could be fixed with collision detection on ghosts or just by disabling it as it is a feature to make the ghosts appear smoother at the cost of over-prediction.
the way the interpolation works is it creates a start point (of the ghosts position) when the networked position is changed,
at extremely high speeds the distance between the start point and the networked position would be large, so that gap would be interpolated within 50ms (the start and end position will always be interpolated for 50ms no matter the distance, so speed isnt an issue apart from maybe phasing through walls for 50ms in very very VERY specific situation where you somehow get behind a wall faster than the update rate).

@PeeblyWeeb
Copy link
Author

(a.) this is a sort of bandaid solution because if the portals where within that "distance limit" then interpolation would occur, or if the distance value is too low then doing a wavedash would cause jittering/teleporting.

I'm gonna experiment with distance checking from the predicted position instead of the current position and see if that works any better

@ghost
Copy link

ghost commented May 1, 2024

sort of like predicting where they would be predicted within 50ms and when the target position is changed if they arent where you predicted then warp them without interpolation?

@PeeblyWeeb
Copy link
Author

yup, basically that, with a bit of lenience to make sure its not falsely triggered

Comment on lines +181 to +184
Vector2 LastTargetPosition = Vector2.Zero;
Vector2 CharacterPositionAtPacketReceived = Vector2.Zero;
float TimeSinceLastPacket = 0;
Vector2 CurrentPredicted = Vector2.Zero;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't those be private? C# defaults to internal.

CelesteNet.Client/Entities/Ghost.cs Outdated Show resolved Hide resolved
CelesteNet.Client/Entities/Ghost.cs Outdated Show resolved Hide resolved
Dialog/English.txt Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer there being some sort of toggle to turn the lerp off.

@SnipUndercover
Copy link
Contributor

Personally I'm not a big fan, I think this is unnecessary.
How does this look like when experiencing lag?

@PeeblyWeeb PeeblyWeeb marked this pull request as draft May 9, 2024 18:02
@PeeblyWeeb
Copy link
Author

PeeblyWeeb commented May 9, 2024

I have not been able to test this with lag. (unless you mean ping, which i don't think that's what you mean)

@SnipUndercover
Copy link
Contributor

I originally meant ping, but that is also a valid thing to check.

@PeeblyWeeb
Copy link
Author

PeeblyWeeb commented May 9, 2024

I originally meant ping, but that is also a valid thing to check.

then yes, in a previous comment i stated this was tested with ~270ms. whenever possible ill see if i can simulate lag somehow.

@SnipUndercover
Copy link
Contributor

Well, I'd like to see how it looks like with said ping. Would the issues discussed previously be more amplified?

@PeeblyWeeb
Copy link
Author

PeeblyWeeb commented May 9, 2024

I recorded some gameplay of a co-op map with 270ms, ill get that uploaded and send it here for you to view. The gameplay was recorded before the following comment: #135 (comment)

gimme a sec, i gotta go diving in my clips folder for it lol

@PeeblyWeeb
Copy link
Author

PeeblyWeeb commented May 9, 2024

might take a bit to upload but heres the link, its mostly unedited (making sure im not doxxing myself) (clipchamp only exports to 30fps so video is 30fps)
https://youtu.be/K7g0muIJ5Qw

@SnipUndercover
Copy link
Contributor

Okay, while it feels a bit off it does seem like a big improvement. I'd still probably want the toggle to turn it on/off though.

@PeeblyWeeb
Copy link
Author

Okay, while it feels a bit off it does seem like a big improvement. I'd still probably want the toggle to turn it on/off though.

i will give it a toggle!

@ghost
Copy link

ghost commented May 10, 2024

ping wouldn't change anything to do with the client prediction or interpolation

@ghost
Copy link

ghost commented May 10, 2024

the only reason it looks "off" in that clip was because the update rate was too high

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants