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
1
Question by Datester35 · Feb 22, 2015 at 04:28 PM · jointgrappling gun

How do you make a grappling hook?

After playing the Attack on Titan tribute game, I became interested in the grappling hook, and the way the the physics behind it works. Is there a simple way to make something like a grappling, perhaps in scripting, or through any means possible? I have tried using a spring joint, but I have no idea how I could launch something to grapple out into. Basically, what I intend to do, is create a gameobject the launches out from the grappling hook "gun", latches on to a collider, and creates a spring joint, other kind of joint, or simple something that would pull you towards it.

Comment
Add comment · Show 2
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 Mmmpies · Feb 22, 2015 at 09:31 PM 0
Share

Not much to go on but look into adding force, there are plenty of tutorials on bullets and such like where you instantiate an object and send it flying off into the distance.

avatar image mbivol10 · Mar 07, 2015 at 05:48 PM 0
Share

Ok , Ill tell you this much , I have the entire aot script , Except I have no clue how the code works and I also figured that the rope is a part of the animated character sadly I still have no clue of how the code works But I have the entire codes , Camera , character , Hook , Everything , I attatched it to a gameobject and sense they used the character animated few animation errors occur , I am trying to understand the code , But Its difficult it is not black on white , and Im not a c# user that makes it more diffficult for me to understand , either way the answer above with the code has actually a bit of this , And If you start with his code youre on the right path , The Biggest mistery is figuring out the code , I will eventually and then I will let you know After I understand the entire code , but then again I have it , And theres hope :)

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by The Red Mohawk · Feb 22, 2015 at 09:33 PM

In c#, you could 'shoot' your grappling hook gameObject by giving it a rigidbody and use this script within Monobehaviour, attached to the hook.

 private bool inAir = false;
 private HingeJoint grabHinge;
 public int speed.

 //To shoot your hook, call this method:
 void GrapplingShot(){
 rigidbody.velocity = new Vector3 (x, y, z) * speed;
 inAir = true;
 //This is the direction your hook moves multiplied by speed.
 }

 void OnCollisionEnter (Collision col) {
     if (inAir = true) {
         rigidbody.velocity = 0;
         inAir = false;
         grabHinge = gameObject.AddComponent <HingeJoint>();
         grabHinge.connectedBody = col.rigidbody;
         //This stops the hook once it collides with something, and creates a HingeJoint to the object it collided with.
     }
 }

This should get you started. I'm not going to code the whole grappling hook for you.

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 Nova-1504 · Mar 15, 2017 at 01:10 PM 0
Share

Hello, quick question; when I use this script, I get an error (well, three) that say x, y and z don't exist in the current context. Obviously just writing x, y and z isn't correct, however I don't know what is supposed to go there. Little help?

avatar image Kerihobo Nova-1504 · Mar 15, 2017 at 09:21 PM 0
Share

He was offering logic not so much code, we have no idea what your actual x, y, z will be. Basically he is saying you need to have a vector3 that will force your rigidbody in the direction of your grappled target. That Vector3 gets multiplied by your speed.

So let's say you had a method that returns a Vector3 calculated by the direction from your player to the grappled target, it is called 'GetDirection()' or something...

basically change that line to

rigidbody.velocity = GetDirection() * speed;

and GetDirection() would have all the logic inside it for giving you this value.

avatar image hikodiko · Apr 17, 2017 at 08:42 PM 0
Share

hello i have problem with that one can you help me? void GrapplingShot(){ it's saids unexpected symbol 'void'

avatar image Kerihobo hikodiko · Apr 17, 2017 at 09:38 PM 0
Share

sounds like one of your previous lines may be missing a semicolon.

avatar image
0

Answer by J0hn4n · Sep 15, 2017 at 04:44 AM

@Datester35 I think a simple solution its just raycast to where will going your hook. if hits addforce to that vector else do nothing.

Comment
Add comment · Show 1 · 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 DestepYT · Mar 04, 2021 at 07:21 PM 0
Share

It says Assets\Grapplinghook.cs(3,19): error CS1001: Identifier expected how do i fix this?

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

10 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

Related Questions

making a grappling hook/swinging rope in unity 2d? 0 Answers

Configurable Joint - What does Position Spring and Damper mean? 1 Answer

how to automatically create fixed joints in a wall of cubes? 1 Answer

Move mechanical arm with mouse 0 Answers

Problem with Hinge Joint making rope 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