GithubHelp home page GithubHelp logo

unity-workshop---rope-physics's Introduction

Unity Workshop - Rope physics

This is an attempt at creating ropes in Unity, with the following criterions:

  • be affected by gravity
  • respect distance constraints between each segments
  • interact with rigidbodies
  • interact with static colliders
  • stay stable at long lengths
  • stay stable when applying tension

With those set, I had 3 approaches - distance, joints and verlet

Distance Rope

I use multiple rigidbodies that I chain together using a custom DistanceConstraint script. Sadly the way the distance constraint affected the rigidbodies made it extremely unstable.

Pros:

  • interacts with Unity physics (rigidbodies and Colliders)
  • distance constraint more lightweight than joints

Cons:

  • extremely unstable in all scenarios

Joints Rope

I chain multiple rigidbodies together using Unity's built-in SpringJoint. The SpringJoint was chosen as other types of joints start to break when too much tension is applied on them.

Pros:

  • interacts with Unity physics (rigidbodies and Colliders)

Cons:

  • stretches a lot at a high number of points, which can be fixed by setting the Spring value higher
  • intensive at a high number of points

Verlet Rope

By far my favorite, I use Verlet integration and distance constraints on an array of positions. Based on Jakobsen's famous paper, "Advanced Character Physics", it's very simple and efficient but doesn't interact with Unity physics which is a major flaw. I added a height limit and came up with a quick and dirty way to attach rigidbodies to the rope and have them affect it, but the results are not perfect.

Pros:

  • visually pleasing results very easily
  • minimal setup

Cons:

  • doesn't interact with Unity physics out of the box
  • a lot more calculations for a little more rigidity

Adapting to VR

The second objective I had with this workshop was a way to use this rope in VR.

I ended up choosing the Verlet rope as a base, since it was not only the most stable but also the most performant: I would get a noticeable amount of fps drops on Quest 2 when using a JointsRope while the VerletRope didn't cause significant fps drops with a higher number of points. Of course, this is probably due to the fact that the VerletRope doesn't interact with Unity's physics.

The initial plan was to be able to use it as a way of locomotion, by throwing then pulling it, but it ended up being too complex for the short time I had and my limited knowledge of the XR Interaction Toolkit. I chose to focus on the interaction between the rope and other rigidbodies in the scene and work with my limitations by making it a hook system.

The end result works pretty well, although it may need a rework to allow for rewinding/extending the rope !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.