[Need a hand!] - Swinging like Spider-Man

Howdy everyone!

Recently, I’ve been trying to add a swinging mechanic into my game; Think Spider-man style.

Basically, The reason I’m here is that I need a hand. I’ve messed up somewhere and I’m not sure how.

As some of you may know, my Pitfall when it comes to Blueprints is: Vector maths AND Physics.

And so you can guess why I am sucking creating this swinging mechanic.

Before you suggest, I’ve already read the grappling hook wiki, checked out Peter’s Attack on Titan system (I even updated all the broken code in 4.7 :>) and I’ve scowered the documentation for HOURS trying to find a solution. But I can’t see to figure it out.

So let me let you in on my train of thought:

I’m thinking that I want to do a two traces in front of the player, Maybe spheres or lines, I’m not sure yet. I can do that just fine. But it’s everything after that that is the problem.

You see (I should tell you now that I’m doing this all in a MyCharacter blueprint), my plan was to add a Physics handle at the trace hit location and then grab the player and just let the default stuff do it’s magic and let the player swing until they let go of the swing button, which would destroy the physics handle.

But putting that into code hasn’t really worked out for me.

An alternative method I’ve been thinking of would be to create a wire in 3DS Max and rig it with bones, then set the top two origin bones (That would stick into the wall) as Kinematic and the rest to simulate in PHaT. So when the Player attaches themselves to the rope, they would be following the natural motion of the wire… But is this something that would work out of the box? It’s only a vague idea at the moment (Haven’t had time to try it out) but as it’s untrodden terriory for me, I’m scared to do it in case I mess up!

Third and final solution would be to cut the mechanic out completely, which isn’t what I want to do.

Oh and yes, before you suggest, I also checked out the complicated mess that is the Swing Ninja’s Grapple Blueprints! (Tut tut to the Blueprint coder at Epic that was so messy, Made my inner-clean freak a bit cross!) - I ALSO checked out the write-up from that dude who did the swinging mechanic for Spider-Man 2. Did it help? Not a bit :smiley:

So yeah, preferably the first method would be excellent, but I have no idea of how to create something psychics like that would stick the player to the wall like a rope so they can swing like they were Tarzan of the concrete jungle. I tried to create a Physics handle but I know in my heart that I’m messing up bad doing that somehow.

TL;DR - Is there an easy way to create a Physics “rope” between the player and a wall so the player can swing on the wall like in the “Awesome” Spider-man games :slight_smile:

So yeah, Any help or pointings into the right direction would be MUCH, MUCH appreciated! I’ve almost teared all my hair out on this, so I’m dying to help!

Thanks in advance everyone!

  • Ryan S

Hi KitatusStudios,

While I haven’t tried it myself (It is on my very long to-do list), we do have a node called “Rotate Vector Around Axis”. Perhaps you could use that with the Axis point being your trace hit location and the “In Vect” being the player forward vector. Try this node and see if it helps you!

Thanks Adam, I’ll give it a go and report back!

Edit: So I gave it a go and it didn’t really do much of anything. At first I thought it was, so I hit the documentation and checked the Answerhub but my set-up was “Working”. I even added a breakpoint and the code is firing, and all the usual blueprint debugging. I’ll keep scratching my head while I get it work but until then, I’m going to try creating a boned mesh in 3DS max and trying that way.

I should be able to report back in a couple hours with my findings, Wish me luck :stuck_out_tongue:

Right, So I’m experimenting with creating a Blueprint which spawns a “Base” at the hit location, then a “Swinger” which attaches itself to the player. Once everything works, I’ll share my BPs :>


Hm… So It’s working kind of. At the start of the game, I’m creating the spawn point and then when the player grapples, The mesh attached to the psyhics constraint jumps to where the player is and they swing as if it were a rope… However!

I can’t figure out how to get the Blueprint to actually move (As “Base” and the scene root are Static, Setting them to movable makes the physics mess up :<)

Any ideas anyone? :<

Edit: Had an idea that I could destroy and create a new one at the location of the hit. But as the hit is on a tick and there’s three directions; This can’t be good for performance! (EDIT EDIT: Yup, 20fps frame loss!)

Alternatively, I could spawn many different “Swingers” in the level and if the player is closest, setting it to the active one (However, this is going to be terrible for the amount of trigger boxes I’ll need (Esp for Direction .etc))

Darn it! So close yet so far! :<

Isn’t this something lile the grapling hook system?

Have you checked this tutorial?

The behavior is kinda like a spiderman swing. You would just need to tweek a few numbers for
the cable component. You could even spawn cables and let them stuck on buildings this way.

There are 2 Parts of this video. I just posted the first one though.


I’ve already seen it but thanks anyway :wink: It kind of helped but didn’t; I spent most of the time updating his code for him (Somebody remind me to send the 4.7 code to him at some point!)


Yeah seems to me a cable actor could work well, I have use a few for swinging objects like that. You could also use a force actor to give your character more control to simulate pulling on the cable or moving your body.

Oh, sorry. I took the tl;dr way :X

There is a new movement component called “rotating movement” component, maybe give that a try? I’m immensely interested in seeing where this goes as I want to update my grappling hook tutorial to allow swinging movement as well as the standard direct-pull that it currently does.

Oh excellent, I’ll give that a try! I originally used your tutorial to get the basic mechanics in and then tweaked them with the cable system to make a web swing type deal; I’ll be sure to share my changes once it’s all working :slight_smile:

I was thinking of going along that root; But I’ve left finding out how the force works until the last minute :stuck_out_tongue: Let’s hope it works to my needs! :>

Edit: Just a little update for anyone watching this thread:

So far I can swing from branch to branch = Woohoo! However, as overlap events shouldn’t be ticked, if the player goes into another overlap while swinging, It doesn’t know to spawn the next swinger and thus keeps the last one (Which sucks being yanked back to where you were before!)

At this current moment, I’m going to try doing a capsule trace at the player location on an animation tick (Via a “Set Timer” which would loop) for any colliders and do it that way.

I’ll let you know what happens :>

Man, look at this progress! I’ve got progress EVERYWHERE! :smiley:

Note: I also added my current BPs to the end of the video for those interested (Will share all BPs when it 100% works!)

Now, it’s time to mess with forces and get a spider-man swing going :>

PITFALL! https://youtu.be/SoZV8D13WuY?t=4m18s :wink:
Rofl, just kidding, I very much know the feel.

So, I’ve read this thread and was curious as well about this whole rope swing thing. I loved some Spider-Man’s games.
So then I took a look around the internetz and came across this:
(lemme me pretend I understand whatever this dude says)

Judging by the videos you’ve posted you are using physics constraints, attaching the character to the physic handle; So, I came up with a test based on the same setup…
On the PhysX simulation, the physical body will swing based on it’s velocity around the constraint so most of the pendulum math is eliminated by that already which is awesome and makes things much easier.
However, as time pass by the body will always lose velocity and stop moving no matter what, as it’s supposed to be. But for characters that is not ideal since you need a way to make the character ‘swing’ using his body’s weight; just like Spidey does.
What is missing on you character is the pendulum movement influenced by the way a person would manipulate it’s center of mass to gain velocity instead of slowly stagnating at the bottom of the rope system.

Notice that the closer the ball is to the Z axis, the more velocity it gains and that energy keeps the pendulum going. So in my test I’ve added that into consideration to ‘generate’ the pendulum movement.
You could try something like this and see if works for you; whatever the velocity the character is, the pendulum should take it and add to that direction only where gravity creates tension between the handle and the character’s body (when character is in certain angle to the handle and always below it). Hope it helps, good luck :slight_smile:

Wow, This post is a treasure chest of goodies! Thank-you so much! Let me mess around a bit and report back!

Seriously, I never thought I’d come across something that would not only blow my mind once, but multiple times in a single post! Thanks :>

Oh man things went horribly wrong…

As you can see from the video, It messed up. I’m not quite sure why. I mean, I watched both your video and the pendulum explanation and all my code works out (Very similar to yours!) but as you can see, No matter what, It wants to add the force and push the character over the loop.

I have a few ideas on how to fix it, So I’ll get right to it. But if anyone can take a wild guess from just the Video… I’ll be even more amazed. Now I really wish I paid more attention in Math / Physics :>

Edit: By the way, I know about the sharp stop of momentum, I’m working on that (That’s no problem) but that START of the hook losing all momentum? Yeah… Can’t figure how to get the character momentum onto the swinging object without it going all skew wiff :stuck_out_tongue:

A proper Spiderman-II-style system should detach the connection automatically once the connecting cable is totally horizontal (i.e. once further momentum would produce backward horizontal movement).

As I recall that was how it worked; it would auto-detach and you would swing again.

EDIT: I’m wondering if the problem in your velocity transfer has to do with your default CharMoveComp’s max velocity or max air speed velocity settings… Adding Force every tick can shove them above that value temporarily, but once the force stops being added the game is able to decelerate them back to their capped speed.

It might help, as an experiment, to radically increase the max air speed value, just to see if that solves the problem… If it does, the solution might be to temporarily raise that value when in a swinging or post-swinging state to allow the player to build momentum above their usual air control speed.

So you’d de-tach and attach to the next one automatically? Which Spider-man 2? There were a few Spider-man 2’s :wink: I’m assuming you mean the PS2 / Xbox / GC one? :>

If so, then I realized how it seemed it like that, but it wasn’t :stuck_out_tongue: :

I notice in this video however that it isn’t actually connecting to the world, but it’s connecting to somewhere behind the camera and following the player (Giving the impression it’s attached when it isn’t).

I guess this is where my ideas and Spider-Man seperate; I mean the pendulum stuff that they did is perfect and exactly what I’m after. But they don’t have realistic (LOL.) physics in terms of “It would swing like a pendulum and accelerate / decelerate due to gravity” .etc

Now, thanks to educational videos and Blueprints posted, I’ve got the pendulum-effect working! Just have to find a way to launch the character in the velocity (And world direction of the end nub) and it should be looking slightly project-ready :>

Are you overriding the player’s mass?

You may want to add a web/line/cable break when the player is x distance above the grapple point/fulcrum, and probably a small speed boost to simulate the jump. You probably should also break the line when the player begins walking

Yeah, that’s exactly what I’ve been trying and failing with :stuck_out_tongue: I’ll be adding the line break (Only if the velocity is too high), I’ve been thinking of recording 3 or so frames of the rope’s velocity / world location (Dumping the old frames constantly, As you can never know when the Player wants to try and break things :P) and then using that to launch the character after the string is broken.