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 a 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 times, 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 a main movement mechanics and can be used to fast travel across levels if executed well! Unlike Spiderman he doesn't tether to a far away point, only to a short to mid distance tree or structure! This allow for a 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 sometimes to get used to and learn instinctively where it's going to tether but I prefer this casual approach.
Where to tether?
First thing we need to evaluate is where does the player can use his tongue. Some games choose to have fixed point in the world where the player can hook to, and some others like Spiderman 2 where you can web swing from every tall buildings in the world.
I chose to have it tether 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 feedbacks for it, it’s not yet perfect as some demo testers don’t know that they can tether without any feedbacks 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 spherecasts from the player 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. For 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 (direction of the raycast, 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 constraint 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 behaviour inside unity and is more than enough to constrain the player.
Here are my settings:
The sprint joint is instantiated the moment the spherecast hits.
Then you can configure it the way you want.
Put the attached rigidbody 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 moveDirection, then calculate the projectedVelocity 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 rigidbody along the movedirection rotated by the camera’s rotation.
You can go different way from there, add a velocity bump when the player release 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!