2nafish117 / godot-verlet-rope

Rope system inspired by half life 2
MIT License
88 stars 14 forks source link

[Tracker] Port to a c++ module for master #1

Closed fire closed 2 months ago

fire commented 3 years ago

Would you be interested in a c++ module for this?

I could try porting it.

2nafish117 commented 3 years ago

Yeah, please do.

fire commented 3 years ago

I see if I can find some effort when I get stuck on my gltf2 task to do the port to godot engine master. It'll be a non-core c++ module and be less accessible but still workable.

fire commented 3 years ago
2nafish117 commented 3 years ago

I have been meaning to contribute to godot for a while now. I can try porting it to master. For the dependencies, what are the new ways to draw immediate geometry in godot4? I dont see an ImmediateGeometry node in godot4. The VisualServer should probably used anyway since it doesnt have the overhead of immediate geometry. How do you think this should be implemented?

fire commented 3 years ago

Godot 4 uses ImmediateMesh. I'll research your other questions.

fire commented 2 years ago

https://github.com/V-Sekai/godot-verlet-rope is my branch.

I'm having some trouble it. Can you review? Then I can port to C++.

editor_screenshot_2021-12-19T095051

The mesh looks very thin.

https://user-images.githubusercontent.com/32321/146685438-1e8f1336-6b51-451e-a639-ba124fe152d7.mp4

fire commented 2 years ago

Here's a non godot example:

https://twitter.com/R_Nikaido/status/1274142361635876866?s=20

fire commented 2 years ago

Do you think the bug is that you need to go from vector3 to Transform3D?

2nafish117 commented 2 years ago

That is a known problem. In editor mode there is no way to get the position of the editor camera, and so the rope cannot always "billboard" in the direction of the camera. But in play mode it looks correct. If godot 4 has a way to get the position of the editor camera a bit of code should be able to fix it. The last of us rope physics is very impressive. collisions with the environment looks great. but doesn't collide with itself though.

2nafish117 commented 2 years ago

if godot 4 returns the editor camera when calling get_viewport().get_camera_3d() then it should work in editor too.

fire commented 2 years ago

I wasn't able to get this to work.

func _calculate_rope_orientation_with_camera() -> void:
    var camera: Camera3D = get_viewport().get_camera_3d()
    if Engine.is_editor_hint():
        camera = EditorInterface.new().get_edited_scene_root().get_parent()
2nafish117 commented 2 years ago

In terms of what can be improved in my current implementation, here are some things.

fire commented 2 years ago

Will evaluate the list.

Here's the video of the current results.

https://user-images.githubusercontent.com/32321/146817364-c1592a36-f516-4760-bbf1-f4334cffd179.mp4

Edited:

Twisting problems.

fire commented 2 years ago

Being able to select and move the start/end points directly from the editor viewport. Currently you need to navigate through the scene tree and find the one you're looking for. Maybe a system like the bezier curves would be nicer?

This is entirely doable. We added a gizmos (plural) system for skeleton transforms on a single node, it should work here too.

2nafish117 commented 2 years ago

Ye the twisting problem really isnt solvable if its being rendered with quads. at some point one quad is going to get pinched. Ropes with volume would solve it but was a little heavy for gdscript to handle.

edit: half life 2 did not have textured ropes (unshaded black), so the pinch wasnt noticable.

fire commented 2 years ago

Want to break this apart into the Godot Engine proposal format?

  1. Being able to select and move the start/end points directly from the editor viewport. Currently you need to navigate through the scene tree and find the one you're looking for. Maybe a system like the bezier curves would be nicer?

  2. Adding forces to a particle or group of particles from script. Imagine explosions affecting the rope.

  3. Get normal mapping working, it would give some depth to the rope.

  4. Better collisions

  5. If performance allows, having a rope with volume would be nice. 4-16 vertices with smooth shading.

Do you want me to port to c++? Are you ok with requiring the dependency. It's unclear if Godot Engine 4 will accept this but I can make the port.

  1. Rigidbody interactions like hanging a ball from the rope. Probably using pin joints?
2nafish117 commented 2 years ago

https://user-images.githubusercontent.com/40386587/146821708-b72cd2c7-3458-4dcb-abd7-d7b340f07a68.mp4

I did a bit of testing if my current implementation can be used with rigidbodies and pin joints, and it doesnt look too bad.

2nafish117 commented 2 years ago

Are you ok with requiring the dependency dependency on what? By a port to c++ you mean as a module or into godot4? I would prefer if we can get this into godot4. A 2d version of this would also be a nice addition.

fire commented 2 years ago

@2nafish117 Can you write a proposal or point to an existing proposal on godot-proposals?

https://github.com/godotengine/godot-proposals/issues

My gut feeling is we need to poll the community to see their thoughts. Not sure.

2nafish117 commented 2 years ago

ive created a propsal. https://github.com/godotengine/godot-proposals/issues/3704 From reading the main readme i get the feeling this fits more into a module rather than core.