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 /
This question was closed Jul 18, 2018 at 04:27 PM by alien30 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by alien30 · Jul 18, 2018 at 09:44 AM · rigidbodyinstantiatescript.joints

[Problem] Trying to create a rope for a grappling hook

Hello everyone

Sorry if this is not the good place but I never used this forum before.

I'm trying to create a grappling hook for a game. I Have a Hook, HookLauncher and Target. The Hook travel from the hookLauncher to the target by clicking on Mouse button Left and reverse without a problem.

But When I try to creat connected nodes during the hook's movements, it never works. I tried different methods but none of them worked. There is a message telling that a joint can't connect a body to itself.

alt text

Do you have any advises please?

Thank you for your help, The code inside my hook is here.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class RopeScript : MonoBehaviour
 {
 
 
     public Vector3 DestinationHook;
 
 
     public float HookSpeed = 1f;
 
 
 
     public GameObject NodePrefab;
 
     public GameObject lastNode;
 
 
     public bool HookOnDestination;
 
 
     public GameObject Target;
 
     public GameObject HookLauncher;
 
 
 
     public bool Fired;
 
     public bool NodeCreation;
 
     public bool done = false;
 
 
     public float Distance = 1f;
 
     public int NumberOfNode;
 
 
 
     // Use this for initialization
     void Start()
     {
 
         lastNode = HookLauncher.gameObject;
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         transform.position = Vector3.MoveTowards(transform.position, Target.transform.position, HookSpeed);
 
 
         if (NodeCreation == true)
         {
 
             if (Vector3.Distance(transform.position, lastNode.transform.position) > Distance)
             {
 
                 CreateNode();
 
             }else if (done == false)
             {
                 done = true;
 
                 lastNode.GetComponent<HingeJoint>().connectedBody = HookLauncher.GetComponent<Rigidbody>();
             }
 
         }
 
     }
 
 
     public void OnTriggerEnter(Collider other)
     {
         if (other.tag == "Target")
         {
             NodeCreation = false;
         }
     }
 
     public void CreateNode()
     {
 
         Vector3 pos2create = HookLauncher.transform.position - lastNode.transform.position;
         pos2create.Normalize();
         pos2create *= Distance;
         pos2create += (Vector3)lastNode.transform.position;
 
         GameObject go = (GameObject)Instantiate(NodePrefab, pos2create, Quaternion.identity);
 
         go.transform.SetParent(transform);
 
         lastNode.GetComponent<HingeJoint>().connectedBody = go.GetComponent<Rigidbody>();
 
         lastNode = go;
 
     }
 
 }
 
 
     
 
 
 
 

error-unity-rope.png (106.6 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

  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Jul 18, 2018 at 12:23 PM

Good day.

Did you tried LineRenderer Component ?

It allows you to draw a line in 3D, it will not move ( at least not by default).

You should investigate and explore if it can be usefull for your propouse!


The other way i can imagine is a little bit more complex and large to do. Have a prefab called "RopeSection", and use them to create a rope by adding a new section at the end of the lastone, controlling its movements by scripts and child/parents configurations. Is more complex, but you can achieve anything by this way!

Good luck!

Comment
Add comment · Show 4 · 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 alien30 · Jul 18, 2018 at 12:56 PM 0
Share

Thank you for your answer .

I thought about line renderer but I want the rope to move like a real one.

I tried your solution with the hingejoints. Is it not the same?

avatar image alien30 · Jul 18, 2018 at 03:54 PM 0
Share

I've found a way with the Hingejoints but thank you for your advice which gave me ideas for some functions which now works.

avatar image alien30 · Jul 18, 2018 at 03:54 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class RopeScript : $$anonymous$$onoBehaviour
 {
 
 
     public Vector3 DestinationHook;
 
 
     public float HookSpeed = 1f;
 
 
 
     public GameObject NodePrefab;
 
     public GameObject lastNode;
 
 
     public bool HookOnDestination;
 
 
     public GameObject Target;
 
     public GameObject HookLauncher;
 
 
 
     public bool Fired;
 
     public bool NodeCreation;
 
     public bool done = false;
 
 
     public float DistanceNodes = 0.1f;
 
     public int NumberOfNode;
 
 
 
     // Use this for initialization
     void Start()
     {
 
        // lastNode = HookLauncher.gameObject;
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         if ((NodeCreation == true))
         {
             CreateNode();
         }
 
         if (Fired == true)
         {
             transform.position = Vector3.$$anonymous$$oveTowards(transform.position, Target.transform.position, HookSpeed);
             NodeCreation = true;
         }
         else
         {
             transform.position = Vector3.$$anonymous$$oveTowards(transform.position, HookLauncher.transform.position, HookSpeed);
             NodeCreation = false;
         }
         
         if (transform.position == Target.transform.position)
         {
             NodeCreation = false;
         }
 
         if ((NodeCreation == true))
         {
             CreateNode();
         }
         
 
     }
avatar image alien30 alien30 · Jul 18, 2018 at 03:55 PM 0
Share

public void CreateNode() {

     if (NumberOfNode == 0)
     {

         GameObject go = (GameObject)Instantiate(NodePrefab, transform.position, Quaternion.identity);

         go.transform.SetParent(transform);

         HookLauncher.GetComponent<HingeJoint>().connectedBody = go.GetComponent<Rigidbody>();

         lastNode = go;
     }
     else
     {
         GameObject go = (GameObject)Instantiate(NodePrefab, transform.position, Quaternion.identity);

         go.transform.SetParent(transform);

         lastNode.GetComponent<HingeJoint>().connectedBody = go.GetComponent<Rigidbody>();

         lastNode = go;
     }

Follow this Question

Answers Answers and Comments

199 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

Related Questions

Creating a rope in 3D for grappling 0 Answers

Need help with shooting and reload script 1 Answer

C# How to choose a Transform value without drag it from asset folder, only with script ? (sorry the question is not clear) 0 Answers

Unable to find custom classes in PUN2 (PhotonNetwork, PUNClasses) 0 Answers

How do i get an object to destroy another after multiple hits? 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