-
Notifications
You must be signed in to change notification settings - Fork 88
Basic box-based destructibility system with recursive splitting #331
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
… longer edge splitting Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…port Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…matting Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
9a8ef9b to
d5eff6e
Compare
|
@copilot Trying to add destructible plain sprites support to the editor but i might be forgetting something because it hits me with [22:26:18] Invalid "type" property for node "crate". when i try to load shooting_range.json with a "crate" resource. I made CRATE destructible sprite now. Try to fix it for me. Also remember in build_arena_from_editor_project.hpp when you're building a scene to use destructible_sprited_body instead of plain_sprited_body for destructible entities. otherwise there wont be auto destructible = agg.template findcomponents::destructible() inside the editor_rebuild_node.hpp. |
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
…ation" This reverts commit 01580a7.
…ariants::destructible Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
Co-authored-by: geneotech <3588717+geneotech@users.noreply.github.com>
|
@copilot zaokraglaj mi w /gmud punkty do inta i pisz tam ktore ma kazdy miejsce np.
|
The |
Implements destructible physics bodies that split into box-shaped chunks when damaged. Chunks recursively split based on excess damage with staggered delays.
Core System
invariants::destructible:max_health,make_dynamic_below_area,disable_below_area,money_spawned_min/maxcomponents::destructible: runtimehealthandtexture_rect(0-1 UV space for chunk bounds)destructible_sprited_body: new entity type with destructible componentsdestruction_system::apply_damages_and_split_fixtures: processes damage, splits entities when health ≤ 0Splitting Algorithm
new_health = root_max_health * new_texture_rect.area()pending_destructionwith staggered delaysSafe Entity Cloning
Introduced
queue_clone_entityto prevent pool reallocation during iteration:Physics Integration
calc_body_type: static → dynamic when area ≤make_dynamic_below_areathresholdcalc_filters: chunks belowdisable_below_areagetLYING_ITEMfilterfrom_box_shape: scales fixture bytexture_rect.{w,h}Effects
standard_destruction_sound/particleson first splitlesser_destruction_soundon subsequent splits (prevents sound spam)1.0 + 0.4 * (1.0 - area)0.6 + 0.4 * areadefault_coin_flavoursincommon_assetsfor money dropsEditor
health,make_dynamic_below_area,disable_below_area,money_spawned_min/maxOriginal prompt
Basic box-based destructability
Have a new components::destructible added to plain_sprited_body.
In it hold:
real32 max_health = -1.0f;
real32 health = -1.0f;
xywh texture_rect = xywh(0,0,1.0f,1.0f); // in 0-1 space. if 0,0,1.0f,1.0f, was never split yet. (0,0) is top-left in UV space.
The texture_rect will be the overridden u/v coordinates of a given chunk.
In draw_entity.h you should take into consideration whether the drawn entity has a components::destrcutible and if so consider its overridden texture_rect.
Handle these damages in destruction_system::apply_damages_and_split_fixtures like process_damages_and_generate_health_events does.
if max_health == -1 then destructibility is disabled and you can skip damage to that entity in this function.
E.g. sentience system processes its damages in process_damages_and_generate_health_events.
Generating chunks
When health goes below zero we split the entity into two always:
Highlights
Applying damage events to destructible bodies should spawn white pure color highlights, proportional to % of the destroyed health/max_health. If you destroyed 50% of max_health or more, make it 100% pure color highlight. If it's just (hypothetical) 0% health, make it a 10%, barely visibler pure color highlight. so highlight linearly strong with damage.
Destruction effect
Should depend on the physical material (physical_material.h).
Add equivalents of these:
So:
sound_effect_input standard_destruction_sound;
particle_effect_input standard_destruction_particles;
And if they are unset which they will be for now, in logic fall back to standard_damage_sound etc.
Make standard_destruction_sound etc editable in editor.
Transition static to dynamic body
If a plain sprited body is static, the splits might become dynamic upon destruction. If any split becomes <= 60% of the original (determined easily by texture_rect area), make it dynamic as well. Calculate it statelessly in calc_body_type and remember to reinfer both original and new chunk upon destruction event.
Editor
Make a tick "Destructible" and if its ticked then have another property "health". This prop will be written to max_health in the components::destructible.
However tick "Destructible" should be editable ONLY on resources that don't have a custom shape defined because this will obviosuly work only on box-based shapes only for now. We screw circles, polygons etc for now.
Details
Note for things to work correctly you have to consider components::destructible in find_aabb in spatial_properties_mixin.h. A...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.