Hey there! First off, really nice game! The controls take a while to get used to but once you're familiar with them, it's really fun. Especially like the idea of the little orb showing you when you are able to grapple again. :)
That being said, I have a somewhat random question. I am a second semester Game Design student and am currently working on a 2D space game with a grappling hook mechanic (for my exam). Up until now, it has been a massive pain to implement such a mechanic for me and to get it to work properly. I've already spent a lot of time looking for the right solution in various forums and tutorials, without much success.
That's why I'm writing you. Your grappling mechanic looks like it's using a raycast to determine where it can be shot. Is that correct? If so, would you mind if I took a look at the code, to understand how you did it? Not to steal your code, but to finally understand it and get on the right track (hopefully :D)
Have a good week & friendly regards!
Lauritz
PS: Just in case you're curious what the game I am working on looks like, you can find it on my page by the name "Asteroid Dancer" :)
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.
Hey there, thank you very much for the detailed reply! I really appreciate it. I haven't had the chance to fully dig into your code just yet, because of some assignment from other classes. But on the first glance I think I already vaguely understand why the first iterations of my grapple mechanic didn't work out -- which has to do with how the hook is created in the first place and how the layers and collisions work together. In the next few days I will look into that a bit more deeply.
Have a nice sunday and thanks again for your help!
Absolutely amazing. On top of the solid movement system, the level design is also superb. The only complaint is I wish I could see the cooldown on the grapple.
Thank you for playing! I felt iffy about the level design but I'm glad you enjoyed. The orb that follows you is supposed to show you the cooldown for the grapple but I think I should have made it so that it shows how recharged it is as opposed to the binary charged/not-charged.
Really fun! The movement and the way momentum works is very nice.
I think it could be fun to add orbs that you can collect that will reset the grappling hook. That way you could make jumping puzzles based on having to swing along a certain path to make sure you collect an orb which gives you the extra shot you need to complete the maneuver.
Do you have any plans for the player being able to use the rope to get to the point they shot at? The term “grappling hook” make me think I could go to that location once I fired it, but if there was I couldn’t figure out how to.
Thank you for playing! I've put a lot of time into the momentum system and I'm glad it's working. I've been thinking about adding more orbs and that's a pretty good idea for what they could be used for. As for being able to reel into where you've shot, I'm thinking I probably won't implement that as then you would be able to get to any point you can shoot, and I want it to be more of a puzzle to maneuver your momentum to get you there. Thank you for your feedback!
← Return to game
Comments
Log in with itch.io to leave a comment.
Hey there! First off, really nice game! The controls take a while to get used to but once you're familiar with them, it's really fun. Especially like the idea of the little orb showing you when you are able to grapple again. :)
That being said, I have a somewhat random question. I am a second semester Game Design student and am currently working on a 2D space game with a grappling hook mechanic (for my exam). Up until now, it has been a massive pain to implement such a mechanic for me and to get it to work properly. I've already spent a lot of time looking for the right solution in various forums and tutorials, without much success.
That's why I'm writing you. Your grappling mechanic looks like it's using a raycast to determine where it can be shot. Is that correct? If so, would you mind if I took a look at the code, to understand how you did it? Not to steal your code, but to finally understand it and get on the right track (hopefully :D)
Have a good week & friendly regards!
Lauritz
PS: Just in case you're curious what the game I am working on looks like, you can find it on my page by the name "Asteroid Dancer" :)
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.
Pastebin Links:
GrapplingHook.cs: https://pastebin.com/Dy88kMMG
Grapple.cs: https://pastebin.com/f393s7Cb
Hope this helps, let me know if you have any other questions
Hey there, thank you very much for the detailed reply! I really appreciate it. I haven't had the chance to fully dig into your code just yet, because of some assignment from other classes. But on the first glance I think I already vaguely understand why the first iterations of my grapple mechanic didn't work out -- which has to do with how the hook is created in the first place and how the layers and collisions work together. In the next few days I will look into that a bit more deeply.
Have a nice sunday and thanks again for your help!
Absolutely amazing. On top of the solid movement system, the level design is also superb. The only complaint is I wish I could see the cooldown on the grapple.
Thank you for playing! I felt iffy about the level design but I'm glad you enjoyed. The orb that follows you is supposed to show you the cooldown for the grapple but I think I should have made it so that it shows how recharged it is as opposed to the binary charged/not-charged.
I really enjoyed playing your game! The physics were fantastic and the grapple is such a cool mechanic! I feel like Levi Ackerman!
This is a great concept. I want to see how this game develops into the future!
Thank you for your feedback! I'm thinking about trying to turn this into a full game so we'll see what happens.
Really fun! The movement and the way momentum works is very nice. I think it could be fun to add orbs that you can collect that will reset the grappling hook. That way you could make jumping puzzles based on having to swing along a certain path to make sure you collect an orb which gives you the extra shot you need to complete the maneuver. Do you have any plans for the player being able to use the rope to get to the point they shot at? The term “grappling hook” make me think I could go to that location once I fired it, but if there was I couldn’t figure out how to.
Thank you for playing! I've put a lot of time into the momentum system and I'm glad it's working. I've been thinking about adding more orbs and that's a pretty good idea for what they could be used for. As for being able to reel into where you've shot, I'm thinking I probably won't implement that as then you would be able to get to any point you can shoot, and I want it to be more of a puzzle to maneuver your momentum to get you there. Thank you for your feedback!