Skip to content

Conversation

@lhofhansl
Copy link
Contributor

Another one of my perhaps controversial proposals.

This adds smoothing of two server steps of rotation and position to non-physical CAOs.
For physical CAO, this smooths positions over 5 client step, unless there was a collision, in which the change is applied in one step as before.

I have had this one for a bit now, and it really smooths things, without compromising immediacy in the case of a collision. The transition from client smoothing to no smoothing is not/barely visible with the numbers I picked.

This work well with #16501

To do

This PR is a Work in Progress.

It needs testing. Please try it out!

How to test

Attach to some moving entities (steampunk blimp, hot air balloon, whatever), notice how the world around you "stutters" far less as the entities moves with you attached.
Throw some object (f.e. drop them from your inventory with 'Q' and observer their trajectory).
Observe rotations, etc.

There should be no (or not noticeable) changes to movement and rotation, but position and rotation updates should be smoothed.

@cheapie
Copy link
Contributor

cheapie commented Oct 11, 2025

This definitely seems to smooth out the jitter in celevator quite a bit when going up, which is nice. It also doesn't break the down direction (which was fixed in some other commit a few months ago).

Before: Video
After: Video

@lhofhansl
Copy link
Contributor Author

Thanks @cheapie . I could also make the smoothing configurable.

@sfan5 sfan5 changed the title Add smoothing to content_cao Add movement smoothing to CAOs Oct 12, 2025
@Desour
Copy link
Member

Desour commented Oct 12, 2025

Tested a tiny bit.

Marked a dropped item with branding iron, then did /lua branded("obj:1"):set_pos(here:offset(1, 0, 0)) (branded is just a shorthand for testtools.get_branded_object.) while flying in air. (Can also be observed (but harder to see) by just dropping an item.)
With PR the item teleports to ground before it hit it.

(Tested in singleplayer with 60Hz dedicated_server_step, but resetting to default didn't make it better.)

(But please note that I don't properly understand this smoothening, neither why we need it or why it should be increased nor how it works.)

@lhofhansl
Copy link
Contributor Author

lhofhansl commented Oct 12, 2025

With PR the item teleports to ground before it hit it.

Thanks @Desour! Could you explain a bit more what that means, and how it should behave?
Maybe you are seeing the transition from smoothing to the exact position when a collision is detected.

why we need it or why it should be increased

Client and server both estimate the position of objects, so that movement is seamless between server updates of the position.
Entity position updates get choppy when client and server disagree slightly on the position of an object, due to rounding, etc.
That is noticeable especially with a busy server. You can see this by observing mobs, when they move and then seem to reset. Or when you are attached to a moving object and the whole world around you jiggers (because the position of the object you are attached is corrected when then server sends its update).
This PR uses the existing smoothing logic, and increases that to multiple frames - unless there is a collision when time precision is wanted.

Tested in singleplayer with 60Hz dedicated_server_step

Singleplayer mode does not honor dedicated server step - unless you also apply #16501

@Desour
Copy link
Member

Desour commented Oct 12, 2025

Thanks for the explanation!

If the client prediction is correct, there should be no unsmooth jumps, ideally (there are, because it's not ideal). Even if the server step time is slow, it doesn't necessarily lead to misprediction.
#15014 is probably the correct way to fix this.

Could you explain a bit more what that means, and how it should behave?

It first falls, then teleports down.
It should not teleport (after the teleportation to air via chatcommand).

bla.mp4

Maybe you are seeing the transition from smoothing to the exact position when a collision is detected.

Probably.

Tested in singleplayer with 60Hz dedicated_server_step

Singleplayer mode does not honor dedicated server step

But it does affect packet send intervals (at least last time I checked, IIRC).

@lhofhansl
Copy link
Contributor Author

lhofhansl commented Oct 13, 2025

Thanks @Desour .

What you see is indeed the switch from smoothing to a collision update (which is done in the same frame. So it looks bit like a teleport.) It's either that or always jitter. :(
BTW, that effect is less if you reduce the client dtime smoothing from 5 to 4 or 3 frames, of course then some of the smoothing effect is reduced as well.

#15014 is probably the correct way to fix this.

I doubt this. That issue talks about another source of jitter: Dropped or out-of-order packets and latency.

You'll see jitter with both client and server on your machine with no dropped packets, perfectly sync'd clocks, and practically no latency (< 10us).
Euler/Runge-Kutta integration will have rounding problems, and there will be jittering, and no amount of time/packet syncing will fix that aspect.

Maybe this will just be another change in my ever growing local patch set. :(

@lhofhansl
Copy link
Contributor Author

@Desour Could you try again with the smoothing spread to 4 frames instead of 5?

@Desour
Copy link
Member

Desour commented Oct 18, 2025

@Desour Could you try again with the smoothing spread to 4 frames instead of 5?

Sure. But can you not reproduce?

Still happens with 4.0f.

@lhofhansl
Copy link
Contributor Author

@Desour I see that effect. I think it's not avoidable, we want some smoothing, but for a collision we need precision. My question was more whether it's acceptable with 4 instead of 5.

@Desour
Copy link
Member

Desour commented Oct 18, 2025

🤷 It's still noticeable. And if reasonably possible I personally don't want to see the effect at all (because I'm perfectionistic). But I don't think I should be the one to decide on the tuning value here if there's a tradeoff.
TL;DR: idk

@lhofhansl
Copy link
Contributor Author

lhofhansl commented Oct 19, 2025

@nerzhul
Copy link
Contributor

nerzhul commented Oct 29, 2025

@lhofhansl while it sounds good on paper, did you tested it with 50 entities ? I think we should see it better with more entities

@lhofhansl
Copy link
Contributor Author

@nerzhul I tested it with that birds mod, which creates 100's of entities. I also tested with nssm (created 2000 of those some of the creatures).

This PR just expands the existing smoothing when there is no collision, and does not add any new computation.

What would you expect would be different with more entities? Should I test for something specific?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants