Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hey there, Lauritz. Thank you so much for checking out my game, I appreciate the feedback. 

Regarding the grappling mechanic, I'm actually utilizing the physics system in Unity rather than raycasts. The code is a little messy but I'll add some links to the grappling system on pastebin anyway. I'll try to explain what I'm doing as that may be a little more helpful than digging through my spaghetti code.

The grappling hook system consists of 2 main components, the "GrapplingHook" (I sort of think of it as the gun) and the "Grapple" (the projectile fired by the grappling hook). You could certainly do the "Grapple" part with a raycast instead of shooting out an actual physics projectile. When the grappling hook is fired the grapple projectile gets shot out and has a GameObject variable for storing what it is attached to initially set to null. When the grapple collides with something it checks to see if it is in the "grapplable" layer specified in the GrapplingHook script, and if so it sets its attachedTo variable equal to whatever it has hit. Otherwise, if it has hit something not grappleable or goes beyond a maximum range an UnGrapple() method is called to reset the grappling hook.

At this point we can fire the grappling hook and tell if the grapple has hit anything. Now I messed with a distance joint attached to the player object to get the physics behavior I wanted whenever the grapple actually did hit something. The details of this are in the Grapple.cs OnCollisionEnter2D() method. On the DistanceJoint2D I was sure to check Max Distance Only so that there isn't an unnatural feeling pole vault behavior where the grappling hook cannot reduce it's length.