Search Unity

Grapple and Swing

Discussion in 'Scripting' started by ZhavShaw, Jul 27, 2017.

  1. ZhavShaw

    ZhavShaw

    Joined:
    Aug 12, 2013
    Posts:
    173
    First of all, I'd like to thank you for reading and attempting to help me.

    So I'm in a bit of a pickle trying to create a grapple system for my game. It has quite the amount of specific needs, and it's broken down into multiple parts. Luckily, that's a good thing, as I can tackle each part one by one.

    What I am looking for:
    - An idea of how I should go about tackling this system
    - The components I should try to use to achieve the right outcome for each part
    - (If possible) The right settings for these components

    The system
    The player is made using rigidbody, so I'm applying force to get it to move where I want it to.

    The first part of the grappling system is for the player to choose a location of where they want to grapple and shoot the hook out towards the location.
    This part I have finished. What I did was, simply shoot a raycast towards the intended position, and used Vector3.MoveTowards() to move the hook towards the hit point.

    The second part is what has me hanging. When a button is pressed, the player needs to move at a constant speed towards the target without overshooting it. In other words, it moves directly towards the target, and as it reaches the point, it just hangs there.
    I've tried a number of things, one that I can remember is getting the difference between the hook position and player position, normalizing it, and adding force to the rigidbody to move towards that normalized value as velocity changed.
    This almost worked, but it didn't seem to move the player at a constant speed, and it kept overshooting him.
    Another one I tried was movetowards, then after it came close to the intended position, apply the velocity after, so when I let go of the button, it continues in the direction. Although, this felt clunky, but I should have probably tested it more.

    The third part is the part I couldn't even begin on. I have literally no idea how to go about this. If the player is grappling, and let go of the button that moves it towards the position, it should keep the velocity, but move around the object. It's hard to explain, but say you have a rope that can extend and contract on will, and the player is attached to that rope, and the other end is attached to a static object. The player can reel in the rope to move towards, but as he stops reeling in, he keeps his velocity, but at some point, he turns and starts to swing around that static object.

    This is what I'm looking to achieve. Sorry if it seems like I'm asking you to make a full system for me, it's not my intention. I'm just looking for an idea as to how I should go about doing this, or what I should use to go about doing this.

    Thank you very much for reading my wall of text and attempting to assist me!