Closed geneotech closed 6 years ago
physical_material
struct follows a very similar schema to recoil_player
(regarding assets and ids, though no instances of materials), and is used to generate collision sounds in sound_existence_system::create_sounds_from_game_events
Updated preferred file locations:
src/game/assets/recoil_player_id.h
src/game/assets/recoil_player.h
src/game/assets/recoil_player.cpp
I have following issues which render last task related commit incomplete:
recoil_player_instance
reside? For now, it's inside gun_component.h
cooldown
since I don't know details of it's usagegun_system
code
rigid_body_of_gun
and don't know if is there any weapons to test it on, so for now it's untested crippled version of old codeCROSSHAIR_RECOIL_BODY
is a mess based on the old code, since I didn't understand logic behind it's application by angular_impulse
function and not sure what offset of a recoil_player
represents in general.vec2
offset characterize? I've added some GENERIC
recoil player with offset directed backwards relative to X axis, with normally distributed angle in range of [-pi; pi] and with magnitude of 650-850.game/hardcoded_content/test_scenes/test_scene_recoil_players.cpp
. Location I've chose based on other assets paths. Probably there is better place to do so.recoil_player_instance
reside within recoil_player.h
.recoil_player_instance
should have some "heat" variable by which to determine the index of the next recoil to apply. void cooldown(float amount_ms);
is supposed to decrease that heat, as if the gun was cooling down.rigid_body_of_gun
be unconcerned with recoil. Only recoil_body
variable (crosshair's recoil body) should be acted upon with recoil_player_instance
.vec2
like it was before, just angular values represented by a float
. These should multiply the angular impulse that is applied here: recoil_body.apply_angular_impulse(
total_recoil_amount * recoil_body.get_inertia() * 10.f
);
And apart from cooldown, that should be all change that's needed in gun_system.cpp
.
The signature should be thus:
float shoot_and_get_impulse(const recoil_player& meta);
(I've just copy-derped the previous one)
The rotation of the character's CROSSHAIR_RECOIL_BODY
determines the angle by which to rotate the character itself, which effectively simulates a recoil effect.
The cooldown should also happen in an else
to this condition:
if (
gun.is_trigger_pressed
&& has_enough_mana
&& has_enough_physical_bullets
&& gun.shot_cooldown.try_to_fire_and_reset(cosmos.get_timestamp(), delta)
) {
Implementation is complete.
There should be two structures:
recoil_player
(global scope) Has a vector of recoil impulses and a parameter for the duration it takes the cooldown to descend from one impulse to the previous. Is an asset. Itsget_logical_meta(const assets_manager& manager) const
shall return therecoil_player
itself as a copy. Has a correspondingassets::recoil_player_id
defined.recoil_player_instance
(global scope) Keeps data that determines the index of the value to be returned as the next impulse. Has methods like:float shoot_and_get_impulse(const recoil_player& meta);
void cooldown(float amount_ms);
If the next impulse is out of bounds, it should return a random value seeded after the current heat.
Add
recoil_player_instance
andassets::recoil_player_id
to components::gun and take use of it in the gun_system.cpp where the force applied upon shot is always in the same direction (if (total_recoil_amount > 0.f) { ... }
). Hint: the recoil player will be obtained by step.input.metas_of_assets.find. If it returns null pointer (player not found), apply no recoil at all.Note: this might be easier to tweak once we have the editor GUI. Hint: use minimal_scene.cpp (former name: one_entity.cpp) and debug_minimal_test_scene = true in config for maximum performance in Debug mode.