I’m trying to create a top down grapple hook for a game about ships. The best solution for the behavior I want that I’ve found so far is using a combination of a pin joint and a groove joint – this allows for you to pass through your anchor but gives you a hard stop when you “reach the end of your rope”. In other words, within a certain radius your movement shouldn’t be limited whatsoever, but when you hit the outer radius of your rope you rotate around the anchor point.
Here’s how it’s set up in my project atm:
My issue is that I want to be able to reel in/let out the rope dynamically, essentially changing the length of the groove joint. As far as I’ve read, that’s both not possible at the moment and not a good idea to do on every frame even if it was.
So far my main attempt to solve this has been to add an additional stop via a characterbody2D that sits at the end of the groove joint and then moves inwards to push the boat towards the center, but I haven’t had much success (too much clipping of the boat through the stopper etc) and it just makes me wish there was a way to update the groove joint that’s been doing it’s job perfectly so far.
Any input or pointers as to how to tackle this would be appreciated
I haven’t used joints at all, but in looking at the documentation, it seems (based on the example in the document of the example of a piston) that length can be interpreted as max length. A piston in a car engine has gas injected into it. The gas is ignited, and explodes, propelling the piston up to the end of it’s length where it is restrained. Then it falls back down by gravity. So here’s a thought experiment:
Let’s say I gave a character a super jump ability, that allowed them to leap 300 pixels, but only straight up. So I implement a groove joint to facilitate this. I want them to go up until they hit the top of the joint. So I adjust the y-velocity calculation to allow them to go up until they hit that length. When they hit the top of the joint, I want gravity to come back into effect, and they fall back down. The joint is there to make sure there’s no wiggle room on the x-axis, and to tell me what the limit is. Because maybe I make super mega jump later that changes the length to 600 pixels.
So I’m thinking that for your grappling hook, you just use the GrooveJoint as the end. The node at the the end should be able to move freely in the groove, shouldn’t it? So I would just let it move along the length, and the length is the farthest it can move - enforced (hopefully) by the physics engine.
My issue is that I want to be able to throw out the rope and have it stop when it hits a target, which means the overall length of the rope (aka GrooveJoint) won’t always be the same. As I mentioned in my original post, I’d also ideally like to be able to change the length live as you’re spinning around the anchor, but I’m not sure if the physics engine will like a dynamically changing joint.
I guess my bigger question is whether it make sense to try and create the behavior I want within the joints/physics side of the engine or if I should just make everything out of characterBodys and add back in the rudimentary physics I need.
Yeah I think you’re visualizing the joint as a static rod the length of the entire joint, when based on what I’m reading it is a groove that length which another item can slide along until it hits the end and stops. The groove isn’t the anchor rope (or chain), it is describing the path that the rope is allowed to travel.
Oh, no I’m using the groove as the item with length. I’m just referring to it as a “joint” since it’s technically a “groove joint” if that makes sense.
I missed the link to the issue before. I just read it. My workaround would be to create a new groove joint anytime I want to change the length and swap it out. If that worked, then I’d worry about optimizing it so it didn’t run every frame.