Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vipaware · Sep 18, 2014 at 06:05 AM · physics2drope

Custom 2D physics of a rope (top-down view)

I have been working on a custom 2D physics for a rope lately which I seem cannot realize due to lack of needed math. It is something that turned out quite more hardcore for me than I thought it would at the start.
I tried PhysX (HingeJoint2D) briefly, and I do not see it working any way with what I planned for the behavior. I would also like to avoid using PhysX completely for this rather basic game.

In short, the scene:

This should be a really basic 2D game without any PhysX used. Rope behavior will work completely in 2D. No gravity needed as rope always laying on a flat surface (in XY axes) and camera looks at it right from the top (on Z axis, a regular 2D unity setup). This is a top-down view. User can tap/click anywhere on screen to drag the rope on a flat surface. Dragging is always occurred on the first particle of the rope (user can’t drag any other part of the rope).

Rope properties:

Swinging. Rope can swing if treated accordingly by user. If user suddenly stops the rope while still holding the tap, so the first particle can’t move, the rest of the rope collapses (tap, quick slide and hold maneuver). If user releases the tap right before a very quick slide of a finger (tap, quick slide and release maneuver), the rope is “thrown” in the direction of the slide, while the body and the end of the rope might not follow directly in the direction of the slide due to their initial curved state. In case of tap, quick slide, brief hold and release maneuver the rope’s first particle would not be thrown, but the rest of the body will push it forward, while rope collapses.

Probably most important property to implement: Smoothness. Smoothness would control how quickly an initially curved rope is straightened when dragged constantly in one direction. Smoothness property equal to 1F would straighten the rope as fast as possible (imagine a golden chain or bracelet initially curved on a glass surface, then you pull it and it gets straightened quite quickly). Smoothness property equal to 0F would not straighten the rope at all. Every particle would follow whatever path the users defined while dragging the first particle of the rope. Not sure what to imagine here to help you understand it, maybe an eel in the water, idk. When smoothness is somewhere in between 0F and 1F the resulting behavior is interpolated accordingly.

Swinging behavior is strongly dependent on smoothness. If smoothness equals 0 swinging is not possible, without regard whatever forces user applies to it, as rope can’t change it’s path (defined by user via dragging) while smoothness is 0.

Most importantly, this smoothness behavior is not actually a property of the rope, but a property of the surface on which this rope is laying. So there can be situations where part of the rope is laying within the area of 1F smoothness (where rope can swing and straighten itself while user is dragging the rope, imagine this area is actually an ice), while the other part of the rope is located within 0F smoothness area, where it can’t swing or straighten itself (imagine this area is some kind of swamp, or oil). In this situation both parts of the rope should behave in different ways but still remain a single rope. Situation when three or four parts of the same rope are located in areas with different smoothness property are also possible as user just can keep zig-zagging between two or more areas continuously. The rope should keep behaving accordingly.

No particle collision. Rope can cross itself anyhow anytime.

No limits on particle angles. Rope can turn 180 degrees at anytime.

So that makes basically two behaviors to implement for a rope, smoothness and swinging (which is dependent on smoothness). And smoothness is a property of a surface, not a rope.

Studying:

I found several resources that I think might be useful.

http://nehe.gamedev.net/tutorial/rope_physics/17006/ This is fully fledged physics model of a 3D rope, it can swing, it has realistic smoothness property of a rope, it can wave and everything. I think I could rewrite it for 2D, remove several unneeded properties like gravity, friction, springiness. As I don’t need that precise simulation, this is a basic 2D mobile game after all. Still, this code lacks variable smoothness factor, as it’s too specific of a requirement, and I’m not sure I could modify the code to work that bit in.

http://processing.org/examples/follow3.html This is rather basic implementation of a rope without any physics in just 35 lines of code. I like complete absence of a physics model, but It doesn't swing, however, it still has nice smoothness similar to a rope. If it was possible to add smoothness to this rope as a parameter (to a surface actually) and if it could swing in described conditions with the help of very basic physics model this would be perfect.

I’m not asking to implement this rope’s behavior, as it would be probably too much of a work, so I shouldn't be asking that. I’m asking for an advice or method I should be reading and diving into that would let me build such a behavior. As currently I have two different approaches for implementation: for swings I could use custom physics model and for smoothness = 0 condition I could use a path that particles would follow. But I have no idea how to mix these two different approaches and how to interpolate the smoothness parameter. And that situation when rope is on several different surfaces (with different smoothness property) completely knocks me out.

Thanks for any help!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vipaware · Sep 17, 2014 at 07:19 PM 0
Share

Is it worth asking the same question on stackoverflow? It's more of a general question about math and algorithms rather than Unity3D.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoseKills · Sep 18, 2014 at 09:39 PM

The ages old Verlet paper from the maker of Hitman's physics is worth a look. It's simple and performant and easy to tweak by adding your own properties to the verlets.

Link

I did this (otherwise rather crappy game :) ) ages ago with the verlet system and it's actually not so far from what you might be looking to implement.

I added some extra constraints to make the tail a bit more stiff...

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vipaware · Sep 19, 2014 at 02:16 AM 0
Share

Thank you for the answer! Played your game and liked the way tail behaved.
I heard about Verlet physics before, it's also used in few of my favorite games, such as Hammerfight and Spewer, and probably in dozens more games that I played.
However, I always sneaked past this technique in my projects for no apparent reason (thinking perhaps Euler integrator is good for everything). I feel, it's time to nail that topic down once and for all. The link to paper you gave me misses the images. I see it like this: http://i.imgur.com/TWBwI0J.png Let me know if it's the same for you. I might look for other versions of this document, if I feel lost with this version.
Thanks for the help!

avatar image NoseKills · Sep 20, 2014 at 01:13 AM 0
Share

Thanks :)

Yeah the images are missing. I can't seem to find a working version of it anywhere anymore.

Also, i didn't follow all the way through with the paper. The most useful bits i took from it were the optimizations they made (rid of SQRT) and general principle of estimating speed with last and current position + the whole constraints & adding forces principles.

avatar image vipaware · Sep 20, 2014 at 07:25 PM 0
Share

Yeah, there is no reason to use SQRT. I'm also skipping that last and expensive bit of the formula, whenever I need to calculate a lot of distances every frame for example.
Paper is easy so far. I'm feeling like it would be very good for me to grasp everything from it.
Thank you for your help! Cheers!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

hinge joint 2d rope flies apart 1 Answer

Object that can rotate freely around a center 0 Answers

2D Platforme Rope 1 Answer

Making a rope that does not affect its attached objects 0 Answers

How to build upon Jongallant's verlet integration rope project 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges