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

Yo! Anyone ever get anywhere with this? Wouldn’t mind digging through a project to suss out your implementation. We’ve been looking at a similar feature.

If you do not mind doing it physics based you could go like this:

  1. line trace away from your character to see if there is an object and then get the impact point
  2. spawn a series of constraints and harpoon segments and connect them all in a frame with each other, your character and the line traced object.

That’s the most accurate way to get swinging physics because it is all done with PhysX in UE4.
The ropes in this video are done like this. Best examples are probably from 1:30, from 1:45 and the sequence starting from 2:02.

https://.com/watch?v=pnHOaVpzk3U

Hey guys, so I figure that I am probably not the only one who has still been struggling to figure out a way to implement this same idea in first person. I finally got something working, and wanted to share it in case anyone else has been searching. This is not the completed version, and I am still very new to Unreal, but hopefully this helps someone out!
For my project, I just want to be able to fire off a grappling hook in a standard first person game, and swing around as appropriate. I am a total unreal nub, so I learned quite a few things while working all of this out:

  1. Applying physics to the first person character is a no-go, pawns seem to use their own internal math for physics (minus gravity) and so you only need to physics when they are uncontrolled and need to ragdoll (frequently death)
  2. Using this knowledge, you can’t really use a physics constraint to link with the player – weird and frequently hilarious results happen
  3. Just need to do the work manually (for my project anyway)
    For me, it really just broke down into 2 steps. (sorry about the messy blueprints, rush job before I head off to RPG night with the guys)
  4. when you create the grappling hook, figure out how far the hook is from your character, where it is located in the world, and a little note that you have a grappling hook
  5. Attached to the tick function of the player (if someone knows a better place to put this to reduce the amount of tick functions, please let me know!) you check to see if you are outside the length of the hook, then apply velocity to the player’s movement as appropriate.

EDIT: just noticed i still have a few of my text output testing nodes that things that fed into them in the screenshots, whoops!
There’s still quite a bit of work to be done, like adjusting the movement or player friction such that it works better when the player is attached to the ground, and updating the grapple point to make this work with a moving or physics based actor, but that’s work for tomorrow. Let me know if you have any criticisms or questions about this technique.

Ok, just another quick update before I head out – made the simple changes to allow the grappling hook to update to a moving object and added the connection to allow it to add a force to physics enabled objects.

It feels a bit like you’re reinventing the wheel. This kind of system already exists in the basic PhysicsConstraint component. This, combined with the downwards acceleration of gravity should give you physically accurate swinging, but you may need to up your mass a bit to get the spiderman feel.

Well that was actually the first thing I tried, however with my experimentation the first person character seems to react poorly to having physics simulated on it or its components, resulting in odd behavior with the inherently non-physics based movement that the character uses – the player was unable to move. But without physics simulation enabled the physics constraint component doesn’t do anything. I’m probably missing something but I haven’t found a way to get physic simulation on the player to work well at the same time as maintaining the core movement system, do you have any suggestions?
I suppose that it is worth mentioning that for my project I am not doing the same thing as KitatusStudios’s spiderman-like project but instead am adding a grappling hook / bungie cord to a first person shooter, I may have been unclear.

I’ll just drop that here. Not exactly spider man swinging but with the same principle and some extra forces pushing the character upon constraint attachment, you can achieve the same behavior. Constraints on runtime are tricky nevertheless.

https://www…com/watch?v=VolVi7_GnmM&list=PL1v7L5pwiJuM7XPbUCozcehBcX-wXf60P&index=2 (Just go to target)

https://www…com/watch?v=XbIsV-Mt9II&index=3&list=PL1v7L5pwiJuM7XPbUCozcehBcX-wXf60P (Swing)

[=;536320]
Well that was actually the first thing I tried, however with my experimentation the first person character seems to react poorly to having physics simulated on it or its components, resulting in odd behavior with the inherently non-physics based movement that the character uses – the player was unable to move.
[/]

There is this Unity game Worlds Adrift which is running a mix between animated character and physics swinging. It still looks a bit dodgy when the character is swinging because it seems to be only one constraint that is used and the rope could as well be a long stick, but at least they got the mix to work. The animations also need some work.

But as you say, for true swinging you need to run all physics based.
Like the angular momentum that kicks in when the ropes are fully stretched at the balloon at 1:50min in the R.C. Bot Inc. gameplay footage above, such a realistic swinging is really only possible all physics based.

https://.com/watch?v=LM2QZXXy8Rc

Anyone still interested in figuring this out?
If so, Insomniac Game’s E3 trailer inspired me to try my hand at recreating the locomotion from Spider-man 2,
here’s my progress so far.
https://.com/watch?v=j64V0LVkSy0

Looks like a solid start (: I don’t need it though, but I would be interested in how you’ve achieved the current state.

[=Bankworthy;548024]
Anyone still interested in figuring this out?
If so, Insomniac Game’s E3 trailer inspired me to try my hand at recreating the locomotion from Spider-man 2,
here’s my progress so far.
[/]

That’s looking really good so far! Great work!

[=;548211]
Looks like a solid start (: I don’t need it though, but I would be interested in how you’ve achieved the current state.
[/]

For this method,
to start swinging
I fire out a bunch of raytraces into the world from the character and save the hit locations and length of the traces
Hit locations are only saved if the tether length is shorter than the hit locations z value, (use z = 0 for the ground plane)
This means that the player will only tether to points they will clear the ground with when swinging.
Then a tether point is selected, right now it’s a random choice, but I intend on making a decision matrix to decide the best tether point.

For the actual swinging pendulum physics
On tick, I find out how much of the players velocity is in the direction starting from the tether looking towards the players current position = velocity dotproduct (playerlocation - tether point)
an equal and opposite force is applied to the player (add force), I also apply a corrective force (in the direction of the player to the tether point), to bring the player’s distance to the tether point right again, the equal and opposite force isn’t quite enough.
For the Web Wrapping
When the player is tethered, a line trace is cast from the player to the tether about 9/10s of the way, during free swing, this should never hit anything, so when it does it means that the web has collided with something, I then make this hit location the tether point
That’s pretty much it so far, I use a beam emitter for the web and single frame animations as placeholder.
Next to do is the charge jump and getting the character to face velocity on all 3 axis.
Gaining height is also quite difficult right now so the sprint/swing boost is on my to-do list.
https://.com/watch?v=piEMZ138xKE

The bumping you see during some swings is because of my sub 60 frame rate whilst recording, the physics is still framerate dependent, for now
Thanks!

[=Bankworthy;548705]
For this method,
to start swinging
I fire out a bunch of raytraces into the world from the character and save the hit locations and length of the traces
Hit locations are only saved if the tether length is shorter than the hit locations z value, (use z = 0 for the ground plane)
This means that the player will only tether to points they will clear the ground with when swinging.
Then a tether point is selected, right now it’s a random choice, but I intend on making a decision matrix to decide the best tether point.

For the actual swinging pendulum physics
On tick, I find out how much of the players velocity is in the direction starting from the tether looking towards the players current position = velocity dotproduct (playerlocation - tether point)
an equal and opposite force is applied to the player (add force), I also apply a corrective force (in the direction of the player to the tether point), to bring the player’s distance to the tether point right again, the equal and opposite force isn’t quite enough.
For the Web Wrapping
When the player is tethered, a line trace is cast from the player to the tether about 9/10s of the way, during free swing, this should never hit anything, so when it does it means that the web has collided with something, I then make this hit location the tether point
That’s pretty much it so far, I use a beam emitter for the web and single frame animations as placeholder.
Next to do is the charge jump and getting the character to face velocity on all 3 axis.
Gaining height is also quite difficult right now so the sprint/swing boost is on my to-do list.
https://.com/watch?v=piEMZ138xKE

[/]

I got some kindof mechanic working (grappling on ratchet and clank) but it needs more polishing (such as a downward force applied right after the constraint is created, better mid-air controls, smooth camera movement). I just added a constraint component then detect edges of buildings/points you want to swing from, attach the one part of the constraint to the actor, the other one, spawn a placeholder actor that you are just going to use it’s root component. Be careful, don’t attach both ends at runtime because bad stuff happen.

You can tell by that that I used physics constraints which prooved to be not that good choice. I tried pendulum movement (and remembered some physics from school) but no luck with that’ some of my forces were off (and I still don’t know why). How did you make spidey over here to align with the web? (changes in roll and pitch).

Oh and change the actors tick group to physics(or something like that) in order to be independent that framerate!

[=Zarkopafilis;548748]
I got some kindof mechanic working (grappling on ratchet and clank) but it needs more polishing (such as a downward force applied right after the constraint is created, better mid-air controls, smooth camera movement). I just added a constraint component then detect edges of buildings/points you want to swing from, attach the one part of the constraint to the actor, the other one, spawn a placeholder actor that you are just going to use it’s root component. Be careful, don’t attach both ends at runtime because bad stuff happen.

You can tell by that that I used physics constraints which prooved to be not that good choice. I tried pendulum movement (and remembered some physics from school) but no luck with that’ some of my forces were off (and I still don’t know why). How did you make spidey over here to align with the web? (changes in roll and pitch).

Oh and change the actors tick group to physics(or something like that) in order to be independent that framerate!
[/]

Thanks for the advice, I also tried using physics constraints for the swinging but couldn’t get my head around that, preferred to do the math myself
I used substepping, setting the actors tick to during physics and smoothed out the tether forces math, it seems to have fixed the most severe bouncing

For aligning the character to the pendulum, I only change the rotation of the mesh, leaving the capsule component alone


This is coming off of event tick, if the player is tethered to something

I made a little headway in implementing a charge jump mechanic, Spidey can gain some serious speed from falling
I’m currently using a gravity scale of x2, default felt far too floaty
woosh!

https://www…com/watch?v=QVC8zv3YHXk

[=Bankworthy;553022]
Thanks for the advice, I also tried using physics constraints for the swinging but couldn’t get my head around that, preferred to do the math myself
I used substepping, setting the actors tick to during physics and smoothed out the tether forces math, it seems to have fixed the most severe bouncing

For aligning the character to the pendulum, I only change the rotation of the mesh, leaving the capsule component alone


This is coming off of event tick, if the player is tethered to something

I made a little headway in implementing a charge jump mechanic, Spidey can gain some serious speed from falling
I’m currently using a gravity scale of x2, default felt far too floaty
woosh!

https://www…com/watch?v=QVC8zv3YHXk

[/]

I’ve had some issues with floaty movement. Why don’t you try applying some downward force one time only when spidey has just started grappling? It kindof makes the movement feel AAA imo. Also play a bit with the camera’s spring arm, making it go more back based on speed or change it’s FoV :smiley:

[=Zarkopafilis;553104]
I’ve had some issues with floaty movement. Why don’t you try applying some downward force one time only when spidey has just started grappling? It kindof makes the movement feel AAA imo. Also play a bit with the camera’s spring arm, making it go more back based on speed or change it’s FoV :smiley:
[/]

That’s some good ideas, I’ll try some of them out
settling with x2.8 gravity scale for now, just feels better
Dynamic FoV driven by player’s velocity would be coolios

I can’t remember how the games did it best, but was it R2 for swinging to the right, and L2 for swinging to the left?

Looks awesome! :slight_smile:

That looks fantastic! I would love to use a system like this myself, I have other things to work on first .

Hello!
I just found this thread, because I had the same problem.
Your explanation did it, Bankworthy. Thank you! :slight_smile:
For everyone who didn’t understand his words or is just lazy, here is the Blueprint of the basic rope stuff (no web wrapping, TetherPoint is set at view center).

Nicely done! I later found out that the additional corrective force wasnt needed, and that it was the culprit of all the jittery/ bouncyness