Oof that’s an old image I had to reuse! 3D clouds yikes.
So this one is going to be talking about how I did the spide… tongue swing in Crumble! I’ve already talked about it in an 80lv interview I did last month, you can read it HERE.
I’m going to try and expand on that now that I have some time, so here we go:
The tongue mechanic
To move at fast speed or to cross long gaps, our little blue ball uses his tongue as a grappling hook.
In Crumble, it is the main movement mechanic and can be used to fast travel across levels if executed well! Unlike Spiderman, he doesn’t tether to a faraway point, only to a short to mid-distance tree or structure! This allows for better movement and velocity control.
Another point that makes crumble unique is that you don’t need to aim to grapple, only the general direction of the camera is used. It takes some time to get used to and learn instinctively where it’s going to tether but I prefer this casual approach.
Where to tether?
The first thing we need to evaluate is where does the player can use his tongue. Some games choose to have fixed points in the world where the player can hook to, and some others like Spiderman 2 where you can web swing from every tall building in the world.
I chose to have it tethered to anything in the world except some high wall to prevent the player from exploiting the mechanic.
So I tried to make the tongue swings feel natural and minimized the use of visual feedback for it, it’s not yet perfect as some demo testers don’t know that they can tether without any feedback indicating them they can. But I think if you give enough time to the player to learn the mechanics with safe workshops they can adapt easily.
To anticipate where the player can use his tongue I shoot sphere casts from the player’s position.
And as a side note here is the direction of the sphere casts for Crumble 2D sections:
A bit of explanation on what’s going on here.
To create an ideal raycast for our tether, we need to preset directions for it. I created a tool in Unity to help me configure all the different directions and put weight on it. In my case I want the player to tether first in front of him then up then on the sides. The first raycast to touch any authorized physics will return true and will be the one used to create the tether point.
In the code we need to know the rotation state of the camera to rotate the whole system, the quaternion povQuat gets the rotation of the camera.
The ray is the direction “rotation” at the player position, multiplied by the camera’s rotation.
With all that information you can now cast a sphere with (the direction of the ray cast, the radius of the sphere, the output of the sphere cast, the distance of the sphere cast, the layers to interact with, and whether or not to ignore triggers).
In Crumble, I help the player identify where he can swing by moving a flying white and blue circle in the air. But if you want to do a game like bionic commando you can constrain the tether to where you point the camera.
Constraining the tether with physics
Now we need to create the rules to constrain the player’s movement around that hit point.
For this I use a spring joint, this is a very useful physics behavior inside unity and is more than enough to constrain the player.
Here are my settings:
The sprint joint is instantiated the moment the sphere cast hits.
Then you can configure it the way you want.
Put the attached rigid body of the physics you’ve hit and put it in the connected body inside the spring joint. If you want to make a 2D grapple you can skip this and make your own constraint behavior.
Player swing movement
This is the hardest part of the process, now that you have a point your player can hang to, you need to be able to swing to another point like spiderman.
Of course, there is more than that to it, but it’s the main logic behind it.
You get your analog input value with more direction, then calculate the projected velocity of the player based on his velocity and the view tangent. You rotate the player towards this projection and then apply a force to the rigid body along the move direction rotated by the camera’s rotation.
You can go a different way from there, add a velocity bump when the player releases the button, wrap the tether around objects by raycasting alongside it, make the player jumps before he can swing, etc…
Thanks for reading and don’t forget to pay me in wishlists!