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 /
  • Help Room /
avatar image
0
Question by Duodecimus · Feb 13, 2018 at 03:57 AM · 2d-platformercollision detection2d-physicsjointrope

2D wrapping a line around a collision object

Hey there Unity peeps.

So, I have this 2d platformer made out of box colliders. I have the player connected to a point by a LineRenderer and a DistanceJoint2D, for use in physics puzzles.

What I want to do is bend this ''rope'' around objects in the scene, then retract the rope (shorten the distance of the joint), flinging the player around the object. Basically this image:alt text

I know I'll be making a list of positions and then move the joint anchors around whenever it wraps/unwraps, but I'm not sure how to tell when and where it wraps on something.

What should I be using for this?

animation2.gif (5.0 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Duodecimus · Apr 29, 2018 at 05:37 AM

Right, so.


How I ended up doing this was by switching all my platform/wrapping around objects from BoxCollider2Ds to PolygonCollider2Ds. Boxes can't be asked for their corners as they are defined as a center point with height and width, but poly colliders will return a list of Vector2 if you use polycollider.points.


Then, in Update I just sent a raycast from my character to the last point, and asked the object hit for the .points, and compared them to the raycast collision coordinates, and added the closest fit to the list of points.


and to unwrap you calculate the angle of the last three points in the linerender, if it is bigger than 180, snip that last point from the list!


TL;DR

  • Only use polycollider2D for your platforms

  • On update send raycast along rope

  • On collision use .points to get list of corners

  • compare corners to raycast collision point

  • add closest corner to list/linerender/joint/whatever else you need


I was greatly aided by the tutorial found here: www.raywenderlich.com/171250/make-2d-grappling-hook-game-unity-part-1

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 bhavinbhai2707 · Feb 20, 2021 at 09:21 PM 0
Share

Hiii, Can you please post the solution or the script if you don't $$anonymous$$d?

avatar image Duodecimus · Feb 21, 2021 at 05:55 AM 0
Share

@bhavinbhai2707 Here you are, though I would recommend following the tutorial I linked in my answer to get a better understanding of what is going on. https://pastebin.com/xKx4h23w

avatar image bhavinbhai2707 Duodecimus · Feb 21, 2021 at 10:07 PM 0
Share

Hii, Thank you so much for replying. I really appreciate it. The link doesn't seem to work. Can you please re-share it? I just need it for the reference point of view to understand how I want to approach my use case.

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

132 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using a Tilemap Collider 2D, and my rigidbodies keep getting stuck inbetween tiles. Is manually placing Edge Collider 2Ds my only solution? 1 Answer

Sliding animation after running 0 Answers

Why did my character start jumping infinitely 0 Answers

Platform Bounce effect 2d 1 Answer

I just want to understand why when i check Is Trigger on my 2D player he dont collide with any layer but my trigger works fine instead of when i uncheck Is Trigger he collided and works i really want to to knew 1 Answer


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