RigsOfRods / rigs-of-rods

Main development repository for Rigs of Rods soft-body physics simulator
https://www.rigsofrods.org
GNU General Public License v3.0
995 stars 175 forks source link

Attach any two nodes together via mouse #2973

Open CuriousMike56 opened 1 year ago

CuriousMike56 commented 1 year ago

This is a feature request I've been thinking about for a while (plus I'm sure it was requested at least once on the old forums), the ability to attach any two nodes together by selecting them with the mouse. Would give the player a lot more ways to interact with multiple actors. Also would allow you to attach anything that doesn't have ropables. Here's how I'm thinking it could be implemented:

Could also further expand this by also being able to attach the two nodes using ties with a ImGui menu to adjust the strength.

tritonas00 commented 1 year ago

This is a great idea

ohlidalp commented 1 year ago

^I'm thrilled. I've had things like this on my mind for a long time. In fact things like this are the new gameplay mechanic I've been envisioning.

Presently you can't add extra nodes or beams to an actor on the go. The n/b buffers are exact fit. Previously there were pre-defined sizes (1000 nodes, 5000 beams IIRC) but I removed those. My idea is to create one dummy global actor with spare nodes/beams and take from there. It would be a little inefficient with regard to sleeping state, but whatever.

The node highlighting is easy to do, just look into my FlexbodyUI which already has code for calculating screen position of world elements and finding those closest to mouse.

I think it would be fantastic to implement this as script. The node highlighting and selection is already possible: we have DearIMGUI script bindings (https://github.com/RigsOfRods/rigs-of-rods/pull/2840) and game.getScreenPosFromWorldPos() script func https://developer.rigsofrods.org/dc/d63/class_script2_game_1_1_game_script_class.html#ad626d3883bc042fa65726be158a5a48b (added recently). Applying forces to nodes or adding beams is not possible ATM but can be added as I described above. Note there's also game.getMousePositionOnTerrain() https://developer.rigsofrods.org/dc/d63/class_script2_game_1_1_game_script_class.html#ab4a9c422e3f25dd6f4e60925b6ec5405 that I coded for road-editing a while ago, may be useful for fixed nodes. It's also fitting that just a day ago I introduced the RefCountingObject framework in #2971, so you can use that PR as tutorial for adding new script objects.

BTW this is where our existing mouse/actor interaction code lives: https://github.com/RigsOfRods/rigs-of-rods/blob/master/source/main/gameplay/SceneMouse.h, https://github.com/RigsOfRods/rigs-of-rods/blob/master/source/main/gameplay/SceneMouse.cpp - it doesn't resolve mouse/node selection in screen space like I do, but directly in world space by creating virtual sphere around nodes and raycasting to find intersection. There's always more than one way to do things I guess.