Bookshelf icon indicating copy to clipboard operation
Bookshelf copied to clipboard

`bs.spline`: A linear function

Open Stoupy51 opened this issue 8 months ago • 7 comments

🧰 Request Type

Feature

🧩 Feature or Module Name

bs.spline

📝 Description

I know that the initial goal of bs.spline is to make smooth curves, but I'd really like a function like #bs.spline:sample_linear.

The reason is that I'm trying to create smooth cinematic movements. What I've achieved works very well with position but I'm having problems when I try to do the same trick for rotation

https://github.com/user-attachments/assets/fa7668a3-94c0-4096-a734-563836e1f49f

We can see screen shakes in the video, The reason is that I'm using a teleport_duration set to 1 and I think the interpolation of this is linear. When having this value set to 0 it's does not shake but looks like a Powerpoint presentation (20 tps). That's why I would like a #bs.spline:sample_linear function.

This may or may not solve my problem, but it would be a nice feature to have along with smooth curves for other module functions.

Stoupy51 avatar Apr 23 '25 20:04 Stoupy51

Looking back at the video, frame by frame, it looks like the Rotation is not updated every tick but every 3 to 20 ticks. That may be a lack of precision in the results?

Stoupy51 avatar Apr 23 '25 20:04 Stoupy51

Okay, I understand now the problem.

https://github.com/user-attachments/assets/963bb792-a1b7-4b8a-83d4-240a4e595cc5

The server only send significant changes in rotation to the client (more than 1.4°): https://www.spigotmc.org/threads/update-entitys-yaw-pitch-each-tick.331592/?utm_source=chatgpt.com

Stoupy51 avatar Apr 23 '25 21:04 Stoupy51

That’s actually a great idea! I was initially focused on smooth curves, but technically, linear splines are still splines, so it absolutely makes sense to include them in the spline module, even if we don’t always think of them that way.

Also, it’s really nice to see you using the module like this. We’re actually planning a camera module next, specifically to make this kind of setup even easier.

And about the server... just use Fabric 😅

aksiome avatar Apr 23 '25 22:04 aksiome

I'm using a fabric server 💀 The reason for the bug is that the game does not send the new rotation to the client if it's not significant, because the angle are compared on one byte.

Minecraft encodes yam/pitch into a single byte Angle, where:

byte angle = (byte)(rawDegrees * 256f / 360f)

Any change < 360/256 (about 1.40625 degrees) will truncate to zero, and as there is no difference the rotation packet is not sent to the client.

Stoupy51 avatar Apr 24 '25 07:04 Stoupy51

Ah, sorry, I didn’t look into it too much at first. Since it was a Spigot link, I just assumed it was Spigot-related. But after checking the Minecraft Protocol spec, it looks like there’s not much that can be done... I think the best workaround might be to use larger time steps, like running every 5 ticks instead of every tick, and increasing the teleport_duration to match (basically just lerping between each point). This way, you should almost get the same result, and it should even be more performant.

aksiome avatar Apr 24 '25 09:04 aksiome

Oh right, nice idea, I'm gonna try it

Stoupy51 avatar Apr 24 '25 16:04 Stoupy51

I think the best workaround might be to use larger time steps, like running every 5 ticks instead of every tick, and increasing the teleport_duration to match (basically just lerping between each point). This way, you should almost get the same result, and it should even be more performant.

I tried with 0, 1, 5, and 20 and here are the results:

https://github.com/user-attachments/assets/9f5501de-2dab-4c35-90c1-53005e1397e4

5 looks like the best in my opinion, I also tried 4, 6, and 10 but 5 is really better.

Stoupy51 avatar Apr 24 '25 18:04 Stoupy51