Skip to content

Kovnir/Unity-Rope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This simple rope was created for my game, but it is quite generic, so I decided to opensource it. You can use it however you like.

It is made on Unity 2021.3.12, but should also work well on lower or Unity higher versions.

Example

View

The rope visual is made with a simple Line Renderer. To create a curve, I use a Quadratic Bézier, drawing an arc between the two rope attachment points and the Middle Point. The Middle Point will also be shifted down, depending on the length of the rope and the distance between the rope attachment points. You can freely set the Length and the number of Segments for the Line Renderer in the Inspector.

Example

Dynamic Behavior

Time to reveal the secret - the Middle Point is not really used to create the curve. Instead, another point is taken, which tends to take the position of the Middle one.

For this interpolation to be plausible, it must take into account not only the distance to the target, but also the speed (a derivative of distance) and acceleration (a derivative of speed). In general, we need to solve the next second-order equation: $$y(t) + k1 * y'(t) + k2 * y''(t) = x(t) + k3 * x'(t)$$

For this, the Euler Method was used, namely its version - the Semi-implicit Euler Method. The result, though physically not entirely correct, looks quite plausible.

⚠️ The main code was inspired by 👉this video👈 (or rather, even stolen from it)! Be sure to go and watch it, even if you don't want to know how it all works!

You can control three parameters:

  • Frequency - oscillation frequency (higher value - stronger oscillation and faster reaction)
  • Damping - attenuation of the system (less damping - longer attenuation)
  • Response - system reaction speed (0 - smooth start, 1 - abrupt start, -1 - also an abrupt start, but in the opposite direction)

Example

Here is how changing these parameters affects the behavior of the rope:

Example

You can make smooth following in the same way. An example of it is also included in the repository.

Example

P.S.

If you like this Rope, maybe you will like my game as well 😉

twitter

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages