mphe / GDNative-Ropesim

A 2D verlet integration based rope simulation for Godot 4. Written in C++ using GDExtension for fast performance.
MIT License
46 stars 1 forks source link

Rope that pulls on staticbody2ds #10

Open ProbablyIdiot opened 3 weeks ago

ProbablyIdiot commented 3 weeks ago

Hello, I've been working on a game where there are two players that are connected by a rope. The players are made up of StaticBodies and can move independantly of each other. What I need help with is making the rope pull on each player, or at least limit the movement, instead of just creating a gap (video attached as zip, as it is too big). RopeBound (DEBUG) 2024-06-25 12-09-41.zip

mphe commented 3 weeks ago

First thing you should do is change the StaticBodies to CharacterBodies (or KinematicBodies in 3.x). This has nothing to do with this plugin but is a general rule of thumb. StaticBodies are used for static geometry. If they move, they usually shouldn't be static.

Now to the problem: What you are planning won't work at the moment. There is no way to fixate the rope at the start AND end point. That means the player at the end of the rope will always be pulled towards the other player, but not the other way round. Getting a grabbing and pulling logic to work in the first place is a little complicated to explain without example.

I will try to get back to in the next few days, maybe end of the week, depending on whether I find some time. It's been on my list for a while to finally upload a rope grabbing example project.

Also, #9 is slightly related regarding how RopeHandles work and why the gap appears.

If you just want to limit movement, you could also just add a restriction to your player movement code that doesn't allow the player to move further than a certain maximum distance from the other player.

ProbablyIdiot commented 3 weeks ago

Thanks for the info, I probably won't be able to get back to you soon, as I have become ill. Thanks againa though.

mphe commented 2 weeks ago

Small status update: I'm currently working on making rope endpoint behavior more configurable. That means an option whether the beginning and/or ending should be fixed or loose. This should make your use-case possible to achieve. I will also try to include an example project.

ProbablyIdiot commented 1 week ago

@mphe , Sorry for not replying, I've been completely caught up in school tests. I think I'll take the advice on using CharacterBodies and wait for the update. Thanks for the work you do!

mphe commented 3 days ago

So did you already solve it or did you gave up?

ProbablyIdiot commented 3 days ago

@mphe Im just going to wait for the update you mentioned, the game I’m making is just to learn more about the engine, so I’m doing other projects in the meantime.

mphe commented 3 days ago

I'll reopen then until it is solved.

I've been working on an efficient way to completely fixate points and also an option to detach the rope's beginning from the node's position. You can try out on the endpoint_fixation branch or download a build from the latest build workflow. The new version also includes much more example scenes.

I'll also try to get a rope pulling example working this week and add it to the project. The overall setup will be: