bergerhealer / TrainCarts

Minecarts redefined
MIT License
206 stars 64 forks source link

Spinning wheel animations go wild at speed #483

Closed amalon closed 1 year ago

amalon commented 1 year ago

Info

Please provide the following information:


Bug

Description

I have animated some train wheels to spin (with pitch) when the train moves. They work great when the train moves slowly, however at speed the smaller wheels wobble like crazy (i.e. they look as if they're wobbling off center), and when going diagonally (e.g. with TC-coaster rails) the bigger wheels yaw very fast back and forth about the Y axis.

Expected behaviour

Ideally items with a looped pitch animation should animate the same at high speed as at low speed, just faster.

Actual behaviour

Fast animated items (pitch) rotate off center or with non-animated axes (yaw) not matching that of the train as it goes diagonally.

In the following pic the big wheels can be seen at the wrong yaw, and the small wheels at the front have at that moment sunk into the track: 2023-09-11_00 02 33

Here's a stationary pic: https://github.com/amalon/hoganfam-trains/blob/master/docs/a4.jpg

Steps to reproduce

Create a wheel with the following animation:

            animations:
              move:
                nodes:
                  - t=0.25
                  - t=0.25 pitch=90.0
                  - t=0.25 pitch=180.0
                  - t=0.25 pitch=270.0
                  - t=0.0 pitch=360.0
                movementControlled: true
                looped: true
                speed: 0.2
                autoplay: true

Or use the "a4" train from the hoganfam_trains.yml saved train module and the corresponding resource pack found here: https://github.com/amalon/hoganfam-trains

Drive the train at speed along diagonal track and observe from 3rd person view.

Perhaps there is a better way to do the animation so this doesn't happen? Or perhaps due to client side interpolation this will never work? It'd be nice if it could work though, as spoked wheels look really odd not rotating!

bergerkiller commented 1 year ago

Wobbles happen when you export the model in a way that the pivot point (0/0/0) isnt in the center. Simply because minecraft interpolates rotation differently than position. All I can suggest is exporting the model differently in blockbench, so that the center is correct.

For armorstands this pivot point is where the base of the arm or head is.

For display entities this is more complicated

If all else fails, modify the model json manually and edit the transform of the model until it is correct

I dont see the transform or parent/child attachments as you didn't post any yaml so I can't give precise suggestions

bergerkiller commented 1 year ago

I should add that server-side or code-wise there is no solution because of the randomness in how packets arrive at the client. In the interpolation client-side it simply desynchronizes because the linear position interpolation isnt compatible with the rotation.

Oh and I would advice against using hybrid mode as I think display entities and armorstands have different pivot points for the head/arms and stuff. Then it would look good on 1.19.4+ and not on <= 1.19.3 or vice-versa. Stick to using armorstand mode if you can

amalon commented 1 year ago

Thanks, I'll have a bit more of a play and see if I can figure it out.

Currently its using a transform of HEAD, and the wheel was positioned in blockbench by experimentation such that it didn't wobble when moved slowly with minecraft/traincarts. However when I change the X rotation in blockbench's "Display" mode, slot=head it wobbles about a slightly higher pivot in the preview, so I'm a bit confused. Shouldn't minecraft/traincarts use the same pivot? Translation in blockbench display mode seems to apply before rotation, so doesn't change pivot.

FYI the source yml is around here for the big wheels: https://github.com/amalon/hoganfam-trains/blob/master/srv/a4/loco.yml.in#L252

bergerkiller commented 1 year ago

Minecrafts display entity in HEAD mode does not use the same transform/rotate pivot as an armorstand head. Unfortunately.

In HYBRID mode I also make some position transforms myself (to make them the same) and that might trip you up

You might need to add an additional attachment with posy=0.25 or -0.25 with the model to correct for that again. But then itll just look just as broken when using armorstands. Thats why I mentioned using only armorstands for wheels if you choose to make it backwards-compatible

Tl;dr; set position transform mode to ARMORSTAND and pick head there

amalon commented 1 year ago

At speed on a diagonal, the big wheels were yawing like crazy but not wobbling, and were all set to armourstand/head mode.

The smaller wheels at speed were wobbling like crazy but not yawing, and were set to hybrid/armourstand-head mode.

At low speed they all behave.

If I offset the model cubes and set to hybrid / display head it mostly behaves, with a little roll on the bends. This looks the most stable of the options I've tried.

If I use display/head it gets scaled up, so not quite sure if thats usable yet

bergerkiller commented 1 year ago

there is also display/none where you can set your own scale value

amalon commented 1 year ago

Thanks for the help, I've just switched to HYBRID_DISPLAY_HEAD for now, as its a clear improvement.

amalon commented 1 year ago

This is worked around sufficiently for me, and it doesn't sound like much more can be done, so I'll close now. Thanks again