Search Unity

Question Grappling hook combat physics

Discussion in 'Game Design' started by MrJsmall, May 15, 2023.

  1. MrJsmall

    MrJsmall

    Joined:
    Jan 5, 2023
    Posts:
    17
    I am currently working on a parkour fps where the player uses a high tech grappling hook to escape robots in a cyberpunk 2077-esque Tokyo. I would like to make it so that the player can use their grappling hook for both movement and combat, and my idea is to make it so that they can use the hook on an enemy to bring them close, then use a knife or melee weapon to finish the enemy. Kind of like grappling hook kills in Titan Fall 2.
    My question is, how could I implement a system where if you hook an object lighter than you, it comes towards you, and if you hook an object or structure heavier than you, you fling yourself towards it? And if both objects are a similar weight, they meet in the middle?
    How would this look in code? Is it really complicated, or simpler than I think?
    I appreciate any help or suggestions!:)
     
  2. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    it can start simply and then after playtesting you may discover edge cases and areas to polish. handling those situations is where it will grow to become complicated.

    start with pseudo code:
    • Need to classify game objects by weight relative to player, but we only care if they are same, more than, or less than. This can just be a component that holds a variable to store this data. Perhaps an integer where -1 = less than, 0 = same, 1 = more. Or you could make an enum if you want easier-to-read code at a glance.
    • at time grappling hook collides with another game object, need to identify what their weight category is, and from that we can switch to run the appropriate event. "This means that we have to communicate from one game object to another and access that data. Class to class communications is where tons of complexity can occur but to just get this mechanic working you can keep it all very simple and just hard couple the classes together. Once you have the mechanic working, then you can take a refactor pass later to decouple as needed.
    • a couple events to define what actually happens: gameobject moves to player, player moves to other, other and player meet in middle - for any of these, the most basic is just immediate move from location vector A to B. Next step is lerp from A to B. Move one gameobject to a new location is straightforward. For two to meet in middle you have to do a little math but it won't be too complicated and is highly googleable -> given two locations, find middle point between them.
    It helps me to open up a graphic diagram app like figma and draw these events and functions out as boxes. You can see that there is just a couple of big boxes, and then within those a few smaller ones. That way it appears quite manageable and if you feel that you are lost in the weeds while writing the code, you can "zoom back out" and see where you currently are - what is the question you are currently writing code to answer.

    You can refine that pseudo-code a bit, break it down into smaller steps, and then give it to chatgpt and you'll get a workable template to start from. Get that plugged in in the engine and then if you find some problems, you'll have actual working example you can take to the scripting subforum to get help with.
     
    Last edited: May 15, 2023
  3. MrJsmall

    MrJsmall

    Joined:
    Jan 5, 2023
    Posts:
    17
    Thanks, I will give some thought to this. Much appreciated!
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    To be honest, every time I see someone trying to put a grappling hook in a game, I cringe. It's like one of these weird things that developers think is cool. As it usually turns out, it's very difficult to control, it's awkward to move around, it's really quirky and weird. I would recommend trying something else. It's been done to death by people jumping on the bandwagon.
     
  5. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    ah come on. let people put the "monkey" in code monkey :)

    at least its not a vampire survivors clone. i made mistake to look at game dev communities on reddit and that is literally all there is. depressing.

    at least grappling hooks are purely for stupid fun.
     
    BrandyStarbrite and angrypenguin like this.
  6. MrJsmall

    MrJsmall

    Joined:
    Jan 5, 2023
    Posts:
    17
    Agreed! Grappling hooks are crazy fun, and it’s turning out pretty good in my game. I think grappling hooks are one of those things that either turns out crazy badass and fun, or crazy stupid. A balancing act really.
     
    BrandyStarbrite and angrypenguin like this.
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Really? Where have I missed this wave of not-quite-good grappling hook games? Are we talking about released games or prototypes here? I'm struggling to think of 5 commercially released games significantly based around grappling hook mechanics, which probably just means we find our games in different places.

    Anyhow, I'd argue the opposite. If its something that people commonly think would be fun, and it's hard enough that it hasn't been cracked yet, then it's quite possibly a ripe opportunity. Also, I do remember playing two grappling hook game prototypes in the moderately distant past, quite different from one another, both showing promise.
     
    BrandyStarbrite likes this.