Search Unity

3D Grappling Hook!

Discussion in 'Scripting' started by YoloJoe, Feb 8, 2016.

  1. YoloJoe

    YoloJoe

    Joined:
    Jan 20, 2016
    Posts:
    109
    Hello everyone! I would love to add a grappling hook to my game but I have no idea on where to start. There does not seem to be ANY tutorials anywhere on making a 3D grappling hook.
    I found this thread but it's 6 years old and after testing it it does not seem to work anymore. Does anybody know about or have a working 3D Grappling hook script? If not, can we create one together?

    Cheers! :)
     
    Last edited: Feb 8, 2016
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    What kind of grappling hook? The kind you look at a point, click to use and it just drags you towards that point... or something more complex?
     
  3. YoloJoe

    YoloJoe

    Joined:
    Jan 20, 2016
    Posts:
    109
    If not too hard, I would love to be able to use it as a rope with physics and when I press RMB it drags me towards the anchor point.. But I would have to start somewhere, so a click and drag system would be more than good enough for now! :D
     
  4. Magnumstar

    Magnumstar

    Joined:
    Oct 3, 2015
    Posts:
    304
    I think the best method to do this would be have mouse click while in hook mode add velocity on hook in the direction of click using camera.main.screenpointtoray. if it hits a collider with an acceptable tag (layer mask)(wall to hook on), then set grapple hook velocity to 0 to stop it in its tracks and apply the same velocity to your attached player to repel him towards the hook.

    i have no pre made example sorry
     
  5. YoloJoe

    YoloJoe

    Joined:
    Jan 20, 2016
    Posts:
    109
    How would I go about making the grapple stick to what it hits?
     
  6. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    You could make an object which has a pivot at the top of the hook as a sensor , make a box collider on the hook sensor (maybe use a flat plane as sensor) and then make it so when the box collides with whatever you want to hook to the hooks new position is the hookspot. thats how I'd do it, you may want to use a raycast as well...
     
  7. YoloJoe

    YoloJoe

    Joined:
    Jan 20, 2016
    Posts:
    109
    Wouldn't raycast shoot the hook instantly? It would be cool to make the effect of the hook going through the air. To see it fly through the air.
     
  8. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Thatd probably be done with an animation then and obviously the grip could only be used from a distance because of the animation being a certain amount of time. I think not sure, wouldn't dare try make one, id fail haha I just kinda understand how you'd do it.
     
  9. YoloJoe

    YoloJoe

    Joined:
    Jan 20, 2016
    Posts:
    109
    Ok, so I'm now shooting the prefab, it has a tail renderer (I don't know if this is the best way to draw a line between the player and the hook) and it sticks to what it hits. Still don't really now how to drag the player towards the hook..
     
  10. YoloJoe

    YoloJoe

    Joined:
    Jan 20, 2016
    Posts:
    109
    I found this on Reddit:
    But I have no idea how to implement the information into a script... ?
     
  11. GumDev

    GumDev

    Joined:
    Feb 21, 2023
    Posts:
    1
    my grapple hook shoots but doesn pull me