Posted January 26, 2023 by Vrixic
Problem:
How do I make a grappling hook?
Being the first time ever working on implementing a grappling hook can be a nightmare as physics can be the end of a game. I first started to research pendulum physics and learned more about how pendulums work since that's how I wanted the grappling hook to feel.
In Wikipedia, I came across this gif which showed visually how it works. But now the question became how do I implement it using 3D vectors in Unreal Engine? Started to research more and found no posts on how I can convert the pendulum formulas to 3D vectors. As I looked at the gif movement from up above, I realized I had to make use of the dot product to produce the acceleration scalar and the velocity vector. After then another question arose, how can I make the velocity vector change like that in the gif above? So I started to research more and ran into a youtube video of someone making Spider-Man movement in unreal engine 4.
Solution:
In this video, the creator used the dot product of the vector from grapple point to character and velocity to make a pendulum-like effect and it worked fairly well. So I implemented that into my grappling hook, and I started to see some improvement, finally, there were swings. But another problem arose as velocity increased exponentially making the swing physics bug out. I solved this by normalizing the velocity vector and the vector to a character from the grapple point, then dot-producing them to find the acceleration value and creating my own speed calculations. With that finishing touch, the grapple hook was stable and ready to use.
- Vrij Patel, VECCA Developer