BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 311 forks source link

BeardedMath.Lerp appears incorrect for generic types #384

Open NoTuxNoBux opened 3 years ago

NoTuxNoBux commented 3 years ago

Version Number and Operating System(s):

Windows 10, Forge Network Alloy at da8e1295ae1d4fada3037740a4b30df679e4e395 (but the same problem appears to exist in Remastered).

Expected behavior:

BeardedMath.Lerp with some generic type, such as int, eventually reaches the target.

Actual behavior:

The target is never reached.

Steps to reproduce:

Call BeardedMath.Lerp(1, 2, 1), but the original value is always returned.

Context

This may not pose a problem in practice most of the time, because float and double have specific overrides that do work. The generic implementation however always returns a0, which means that the promise of a1 being returned when t = 1 never holds true.

If lerping is not supported for a type, the generic implementation should probably always return a1 instead, immediately reaching the destination. Otherwise, interpolating values gradually over the network will keep trying to get closer to the destination value in YourGeneratedNetworkObject.InterpolateUpdate, but will never reach its destination.

I encountered this for Float3 and Float4 in #310, but noticed this behavior also exists on master and develop, hence this report.

(It is not clear to me how lerping currently works for Unity's Vector3 and friends, as it's not handled here either, but IsInterpolatable claims it is supposedly interpolatable. EDIT: Nevermind, it's InterpolateVector3 and friends.)