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 ImanIrt · Mar 15, 2019 at 02:22 PM · 2dphysics2djoints

Creating a movement script to move up and down a chain (or rope) in a 2D game

I have created a chain using Hinge Joints, now I want my 2D character to grab this chain and go up and down. I want my player to be attached to this chain so that if the chain moves, the player also moves on the chain realistically. (I think I should use a kind of joint on my player too, but I'm confused) What is the best approach to do this?

Comment
Add comment · Show 4
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 xxmariofer · Mar 15, 2019 at 02:46 PM 1
Share

i would use a distance joint from the hand of the player to the end of the rope.

avatar image RobAnthem xxmariofer · Mar 15, 2019 at 03:04 PM 1
Share

Combine that with childing the character to the closest hand joint, and add or remove Y velocity based on input and distance from end point. Then add a function that receives Input to handle attaching and unattaching the player to the rope. Like if he presses an interact key while standing in chain area, it disables player input from normal movement and childs the player to the chain, then changes animations or whatever and waits for Up/Down input to push the player up or down the chain. With left and right, you can add force to the chain to swing it either direction while the player is on it. If the chain is swinging, you'll want to change it from simply adjusting Y velocity, to ins$$anonymous$$d Velocity in the direction of next Upper chain node, or lower chain node if movement is downwards.

avatar image ImanIrt RobAnthem · Mar 17, 2019 at 07:11 AM 0
Share

So if I understand correctly, you are suggesting that I use a distance joint on my character, and when he's going to attach to the chain, I get the closest chain part and attach its rigidbody to my character's dist joint, is that right?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nivbot · Mar 17, 2019 at 08:08 AM

Just attach your player to the chain (make the chain its parent) and then use localPosition of the player transform to move up and down on the chain.

If there’s an issue because each piece of the chain is a separate object you can set the parent to the next link up or down when the player’s collider or the transform is near it

Comment
Add comment · Show 2 · 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 ImanIrt · Mar 18, 2019 at 07:22 AM 0
Share

Thank you, so you mean that I don't need to use joints this way, right?

avatar image Nivbot · Mar 19, 2019 at 05:08 AM 0
Share

What I do with ladders is just set the rigid body gravity to 0 when on the ladder and just move up and down, but since ladders don’t move I don’t need to parent anything.

Since you want the player to sway left and right with the rope it would probably be easiest to just parent the player to the part of the rope he is on then he will move with it, while you will still be able to move the player up and down with localPosition.

That’s how I’d do it anyway. Someone might and probably does know a better way but it should work.

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

205 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 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

What is happening in HingeJoint2D motors? 1 Answer

Set targetjoint2d anchor position at mouse position in 2d 0 Answers

Player freezes upon attaching a "connected body" to a hinge/distance joint 0 Answers

Relative Joint2d: Is there a way limit force to only X or Y axis? 0 Answers

How to give a direction to a hook? 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