# Make character swing from grappling hook

Currently working on a 3D third person game where the character shoots out a ray cast to an object and creates a rope looking arm. The end goal is to have 2 options: if the object is an enemy, pull it to the character; otherwise, if the object is part of the map, the hand of the arm should stick to the object and allow you to apply impulse to the character to swing in any direction while also controlling the length of the arm (being able to lengthen and shorten the arm).

I’ve done some reading and we have the arm attach to the object but I’m not sure how to apply constraints to keep the arm a certain max length. Any help appreciated

You basically have two options.

1. Have a physically based simulation of a rope (this might also simply a straight line rather than an actual rope). In this case you would have another object / actor attached to the two locations and force them to stay at that max distance. (I have no idea how to actually do that).
2. Cheat by simply projecting the velocity on a plane, and then moving the character to max distance if it’s further away than max distance.

The second thing I actually have done. There is some issues with it, especially if you jump pretty much straight down. Nothing unfixable but it’s a bunch of work to get right.

What you do is you take the point you grappled to subtract your current location from that, normalize it to a vector length of one (not sure if that’s necessary but that’s what my script does. Easily done by dividing the vector by the “VectorLength”). Get the node “Project Vector on to Plane”. The V for that node is your Character Velocity. The Plane Normal is the vector we just created. Set that as new velocity. Calculate the point along your rope path that is your “MaxLength” and set your actor location to there. Why is that necessary? Because projecting the velocity to a plane means you always take the current plane and moves you forward on it and in case you are swinging will each tick put you slightly further away from the intended result. Because you technically would want to project your movement along a sphere. Not a plane.

It’s a real dirty hack. Maybe it helps you. Probably not.

Just wanted to throw it out there anyway

Cheers