Creating a 'grapple hook' in 3d

maxccmaxcc Posts: 2Member
edited September 4 in Programming

I'm trying to make a shootable projectile which, when it collides with an object, creates a 'chain' between the point of contact and the player. I'm creating instances of 'links', which are rigid bodies with collision shapes, and pin joints with the nodes set between the links. I'll attach a link to a video, the green squares are joints, pink spheres are links, black ball is the projectile, red square is base joint and blue is tip joint.
https://www.reddit.com/user/Sir_Frankie_Crisp/comments/cyzb5a/ex2/?utm_source=share&utm_medium=web2x

Please let me know if you have any ideas, here's some of the code (attached to the projectile/'tongue'):

---CREATE CHAIN---

if stuck and linkcnt < linkmag and not linked:
    var newlink = linkscene.instance()
    newlink.set_name(str("newlink",linkcnt))
    add_child(newlink)
    newlink.translation = player.translation - (distance_from_player * (linkcnt / linkmag))
    linkcnt += 1

---BUILD JOINTS---

if linkcnt > 0 :
    var tmp
    var loop = 0
    while loop <= linkcnt:
        tmp = str("newlink",loop)
        if has_node(tmp):
            var thislink = get_node(tmp)#               
            if linked:
                var tmpin = str("newpin",loop)
                if get_parent().has_node(tmpin):
                    var thispin = get_parent().get_node(tmpin)
                    thispin.translation = thislink.translation + (distance_from_player * .9)

            if stuck and pincnt <= loop and not linked:
                if loop == linkcnt - 1:
                    tonguebase.set_node_a("../Player")
                    tonguebase.set_node_b(tmp)
                if loop == 0:
                    tonguetip.set_node_a("../Tongue")
                    tonguetip.set_node_b(tmp)
                    var newpin = PinJoint.new()
                    get_parent().add_child(newpin)
                    newpin.set_name("newpin0")
                    newpin.set_node_a("newlink0")
                    newpin.set_node_b("newlink1")
                    pincnt += 1
                else:
                    var nexttmp = str("newlink",loop + 1)
                    if has_node(nexttmp):
                        var nextlink = get_node(nexttmp)
                        var newpin = PinJoint.new()
                        get_parent().add_child(newpin)
                        newpin.translation = thislink.translation + distance_from_player
                        newpin.set_name(str("newpin",loop))
                        newpin.set_node_a(tmp)
                        newpin.set_node_b(nexttmp)
                        pincnt += 1

                        var newmesh = pinscene.instance()
                        newpin.add_child(newmesh)
        loop = loop + 1
        if linkcnt == linkmag:
            linked = true
if not released:
    if linkcnt > 0:
        clear_links()

Tags :

Comments

  • maxccmaxcc Posts: 2Member
    edited September 4

    I looked at the scene remotely while running, and all of the nodes on the pin joints looked correct

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file