Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Collision Dynamically #161

Open
TokisanGames opened this issue Jul 25, 2023 · 2 comments · May be fixed by #278
Open

Generate Collision Dynamically #161

TokisanGames opened this issue Jul 25, 2023 · 2 comments · May be fixed by #278
Assignees
Labels
big terrains Issues that need to be addressed for big terrains enhancement New feature or request
Milestone

Comments

@TokisanGames
Copy link
Owner

TokisanGames commented Jul 25, 2023

Collision for all regions currently builds when a scene runs using the physics server.

There is a debug/show_collision option that builds collision for all regions right then, in the editor and it also works in game. This creates a static body rather than the physics server. If view gizmos is on, you can see it in the editor. You also need this if you want to enable view collision shapes in game.

Collision takes up a lot of memory and is a bit slow to generate. Each region takes 145ms to generate on my system. And running 16k x 8k collision takes about 6gb, or about 48mb per region.

What I'd like is keep the two options of build all collision at runtime, build all collision in the editor, and add dynamic options that will build a much smaller collision mesh around the camera.

The code is already structured into Terrain3D::_build_collision, _update_collision, _destroy_collision, but it's not fully setup to be dynamic yet. So most of the work will be in the middle one. It currently builds a 1025x1025 collision mesh. 1025 because we need one more vertex to get 1024 squares.

  • Provide an option to set dynamic collision mesh size, defaulting to 65x65. I would give fixed options: 33, 65, 127. (Though you could call them 32, 64, 128 as that is the number of squares across). In the set size function, you'll have to destroy_collision and build_collision, if its different and appropriate for the mode (eg don't build in editor if an in game is specified).
  • In build, create the heightmapshape of the specified size.
  • Terrain3D::__process increase the distance_to a bit, 5-10 units, up to a maximum of 50% of clipmap_size so it calls snap less frequently.
  • Terrain3D::snap(), after it sets the position of the meshes, call update_collision to set the position and vertices of the heightmap shape.
  • collision/enabled and set_collision_enabled can be used to toggle it on or off in realitme. If collision isn't built and it's enabled, create collision. Otherwise if collision is built, just toggle it on or off on the physics server, calling PhysicsServer3D.body_set_shape_disabled(). Keep the current logic of if it's disabled, don't build collision.
  • In the collision properties for the inspector (Terrain3D::bind_methods) debug/show_collision can be moved in with the collision group and change to an enum for collision_mode: dynamic in game, dynamic in editor, full in game, full in editor, with the following meanings:
    • dynamic in game (new default, generate 65x65 around player in game w/ physics server)
    • dynamic in editor (generate 65x65 around player in editor & game w/ static body)
    • full in game (current default, build for all regions w/ physics server)
    • full in editor (current debug/show_collision, build for all regions in editor & game w/ a static body)
@TokisanGames TokisanGames added bug Something isn't working enhancement New feature or request labels Jul 25, 2023
@TokisanGames TokisanGames added this to the Stable milestone Jul 25, 2023
@TokisanGames TokisanGames added big terrains Issues that need to be addressed for big terrains and removed bug Something isn't working labels Jul 25, 2023
@TokisanGames
Copy link
Owner Author

I updated the plan for collision options above. set_collision_enabled should be something toggleable, which means it can just talk to the physics server in realtime. Currently it is used only to determine if collision gets built.

@TokisanGames TokisanGames modified the milestones: 1.0, 0.9.1 Dec 16, 2023
@lw64 lw64 linked a pull request Dec 17, 2023 that will close this issue
@TokisanGames TokisanGames modified the milestones: 0.9.1, Beta 0.9.x Feb 4, 2024
@TokisanGames
Copy link
Owner Author

In 4.3, HeightMapShape3D accepts inputs from a normalized image

godotengine/godot#87881
godotengine/godot#87889

@TokisanGames TokisanGames self-assigned this Aug 28, 2024
@TokisanGames TokisanGames modified the milestones: 0.9, 1.0, 1.1 Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big terrains Issues that need to be addressed for big terrains enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

1 participant