Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 CDBiddulph · Jun 03, 2017 at 11:34 AM · physics2dsimulationspringjoint

Simulating a Rubber Band

I'll admit that I already asked a similar question a few months ago, but I didn't get a response and I've been completely stuck on this since then. This is going to be really long, but I hope you'll find it an interesting problem and help give some idea of what to do. So here we go...

I'm creating a game where the central mechanic is launching rubber bands in a 2D plane to solve puzzles. (It is not top-down, so gravity IS a factor.) The rubber bands must hang from one or more pegs at a time, be able to be stretched tightly between multiple pegs, be affected by objects that collide with them, launch appropriately when held taut and released, cause objects to bounce off of them when they are held taut, and break when too much tension is applied.

Previously, I have tried to do this by attaching several objects (the rubber band's "vertices") to each other with SpringJoints and giving each vertex a mesh collider that changes frame by frame to adjust according to its neighboring vertices. This worked decently when the rubber band was unstretched, but as soon as any tension was applied via moving pegs, the band clipped through and fell off. It seems to me that the band needs to have some kind of mechanism to "lock" vertices onto a peg so that it is impossible to clip through. I've come up with what may be a solution, but I have no idea how to implement parts of it.

Give all pegs a mesh collider composed of, say, 25 vertices arranged in a circle.

When a single rubber band vertex collides with a peg, it does not immediately "lock" to the peg, but collides with it as Unity normally would make things collide.

However, when any vertex has BOTH neighboring vertices touching the peg, it will become "locked." (Detecting whether a vertex is touching the peg could be one problem. Unity seems to have no boolean return function like "isCollidingWith" to make this job easier. Would a private boolean variable that switches on and off with OnTriggerEnter and OnTriggerExit really be efficient and reliable?) When one or neither neighboring vertices are touching the peg, it will become unlocked again.

When a vertex is "locked," it will be able to move, but only on the axis represented by the slope of the part of the peg to which it is locked. Think of a one dimensional train on a track, where at any given moment the train can only move forward and backward on the track tangent to the section of the track it is on. The track here is the perimeter of the peg, given by its mesh collider. The vertex is still affected by physics forces, like gravity and the tension in the band, but it is still restricted to its frictionless "track." (This is the main problem; I don't even know how to begin trying to do this. I believe that it is possible to restrict movement on the x-axis or y-axis, but I don't know if it can be done on a user-defined axis. I am not sure how the band vertices will behave when constricted by both their SpringJoints and this track system.)

When the band is pulled taut, the vertices that are not on a peg will be able to stretch and the band will be unable to clip and fall off. (I don't even know how to make the entire rubber band launch appropriately when the peg is quickly released. Maybe I can worry about that later.)

If you've read all this, I really appreciate it. If you have another different and hopefully simpler/more reliable way to do this, I'd like to hear it. If anyone can figure out how to make an object stick to a path and still be affected by physics forces, or a good way to know whether neighboring vertices are colliding with the peg, I would be so grateful. Sorry that this is so long, but making any progress on my project depends on figuring out a solution. Thank you!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

How to make a Spring in a 2D game in unity? 0 Answers

How do I connect a spring joint 2d to a rigidbody in script? 0 Answers

Spring Joint 2D: Can't slow down anchored object while at high frequency. 0 Answers

Are point effectors (2D) simulated when you use the physicsscene2d simulate function? 1 Answer

Drag rigid body based on touch in 2D 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