Basic Spring Module

EDITED: Spring now based on closures. Added github page.

It’s “Euler Physics Spring” simple implementation. For harder purposes I recommend using Chris one based on more complex analytical calculations for absolute accuracy and impressing speed: Physics Based Spring Module V2.0

Hello there! Just made my own version of Spring module and wanna share it with all of you.

5 Likes

I’m wildly confused on the raw code, there’s the vector.create function which I am unfamiliar with, could you explain why you are using it over a Vector3?

im pretty sure the vector library is faster than the normal Vector3 library

1 Like

No offense… but it’s really difficult to believe such a thing if no proven benchmarks have been done.

Roblox’s Vector3 type is the native vector type. They are literally the exact same, and you could even switch between the two without any visible runtime changes (ignoring type-checking incompatibilities). Try vector.one:Abs() or vector.magnitude(Vector3.one).

However, some functions in the vector library are slightly faster than some Vector3 methods as they are intrinsic to the Luau VM and get first-class support for fast calls/native lowering. However, none of those are salient to the resource at hand as it only uses vector arithmetic, so the choice is benign.

Regardless, it’s probably a good idea to write something as simple as this with the native vector type because it makes the library ‘runtime agnostic’ and you could use it outside Roblox. You might run into type-checking issues, though.

Thanks for the explanation; I guess it makes sense to start switching over to using vector

Well actually “Vector3” and “vector” have same usage. Luau “vector” have exactly same functions with Roblox “Vector3”, but it just times faster and more optimized.

That’s… why I said ‘I guess it makes sense to start switching’…?

Well difference is just microseconds (Vector3 vs vector Cross 187 µs > 74 µs) and everyone already used for roblox Vector3. So it just depends on what each developer wish to use.

You shouldn’t switch over unless you are striving for perfect runtime agnosticism or you are in need of very fine-tuned optimization. As I’ve said before, they are exactly the same type, and operations such as basic arithmetic are completely indistinguishable.

The only performance difference is with Vector3-specific features like .Magnitude and :Dot, which you could replace with vector.magnitude and vector.dot if you really wanted to. However, you should only do that if you’re, like, running those calculations a billion times every frame. In the predominant of cases, the differences are negligible.

Well yeah. It all just micro optimizations, but I just used for it already and use it everywhere. It obviously better, but not really enough to make it cost time for switching. Where I really recommend use “vector” is calculations which happening tons of times per second, and requires a lot of math. Like calculating psyhics.

the model link is dead (characters)

Should be good now. I fixed it.

1 Like