Attach player to bones?

I’m testing some game play things for rope climbing in game and am following this tutorial (- YouTube) for creating ropes using bones. I saw that someone in the comments asked the videos creator if you could attach a player to the rope so they could move up and down the bones.
This user in the comment thread was able to get this to work. They wrote “I managed to socket each constraint and I attach the player to each one and move him up and down the chain if he inputs W or S”. My question is how you attach a player to the ropes bones. I can’t find a way. The ‘socket each constraint’ part of his comment also eludes me.
Thanks

1 Like

In UE4, all bones double as “sockets”. Sockets are just a named node in a hierarchy of bones with transform information. So sockets can get placed and customized in the skeleton hierarchy, or you can just use the bones already in the skeleton without adding anything extra.

To attach a character to a socket/bone, use the blueprint function “AttachActorToComponent”. The Target pin should be a reference to your player pawn. The fastest way to get this is to use the function “GetPlayerPawn” with an input “PlayerIndex” of 0. The “InParent” will be a reference to your skeletal mesh component (the rope). This reference can be accessed most easily from inside the logic of your rope BP actor.

Next, the “InSocket” will be a variable with the name of the bone your player is closest to. Keep it simple at first by having each bone name in an array, and on some event call the AttachActorToComponent function with a different element of that array.

Last of all, set the “AttachTargetType”. Most likely, you’ll want to keep the world transformation of your actor.

1 Like

Thanks. This has really helped. I knew it was to do with the “AttachActorToComponent” but I was implementing it all wrong. I have a simple test system now so when I walk near the rope my (using the default FPS bp character) characters location is snapped to the lowest bone on the rope. W snaps me up to the next bone and S down a bone. When I reach either end of the rope I use the “DetachFromComponent” node. This caused me issues cause when I detached I’d either start sliding off in a random direction with no ability to move using WASD or I’d pop off normally but WASD would move me in different directions and speed.

Then I checked what was happening by using a ladder placement function I’m working on. Basically I press ‘3’ and a ladder hologram appears in front of my player that’s normally supposed to orient with the player as I move. But when attached to the bones the ladder starts moving in weird directions that I assume is my player capsule being affected by the bones movement. This isn’t reflected in the default fps weapon that stays looking oriented. I’ve attached a gif. I’m not sure how to solve this.

I’m not certain if this is the issue but…
The attachment will affect location and rotation of the entire actor if the rope sways. But in most games the pawn should always be oriented perpendicular to the ground. Try saving your pawn’s original world-rotation to a variable just before you attach the pawn to the rope. Then after you detach the pawn from the rope, get the variable, and use it to set the pawn’s world rotation, restoring the original behavior.

I’ll try this thanks. Is there any reason my pawn is doing this. It is the default FPS player character from unreal?

I managed to stop the weird rotations by set my player actors rotation to zero just as I detach from the rope. Thanks!