Search Unity

Configurable Joints and Hookshots

Discussion in 'Scripting' started by domilab, Aug 11, 2016.

  1. domilab

    domilab

    Joined:
    Mar 23, 2013
    Posts:
    13
    I've been working the past few weeks to nail down a game mechanic that I can't get right. I'm basically trying to implement a hookshot in 3D space. I want to aim at a object, hook on, and be pulled to the object. I have the raycasting down to properly place the anchor. The problem is getting it to feel somewhat natural. If the character is currently moving in one direction and shoots the hook behind them, I want a nice rounded motion, almost a bounce. I do not want them to move in an exact straight line, I do want gravity to be felt.

    I imagine the solution will be a configurable joint(or possibly spring joint) but I will list what I've tried so far:

    1. I've looked at the current position and the anchor position and just did a lerp on these 2 vectors. This created a very rigid feel. Character will move in a straight line.
    2. I did something similar with a velocity and it's also just very rigid
    3. I tried applying a force to it but it just got moving too fast(I could probably cap the velocity) but it just didn't seem right.
    4. I tried using a spring joint. I thought this was going to be the best approach. However, I can't get it configured properly. It either slingshots the character too hard, is way too bouncy(even with a damper), or the spring just isn't strong enough. I've spent days playing around with different settings of the joint, the rigid body, and even messing with gravity and drag. I just can't get it to work.

    That's when I discovered Configurable Joints. However, anytime I do anything with them, they don't ever behave how I expect. I assumed the drive forces would be my best bet here. I could put a cap on velocity/force, set a target position/velocity, and add the drives. However, I can't get anything behave correctly. Either the character doesn't move or they just go in directions that I don't expect at varying degrees of speed.

    I've been over a few tutorials and I just can't get my head wrapped around it. If you have better ideas on how to implement something like this, I'm all ears

    Thanks!