mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Fall damage _(flops)_
This commit is contained in:
parent
9e841cef1c
commit
1c9822dba2
14 changed files with 106 additions and 23 deletions
|
@ -21,10 +21,12 @@ namespace ml_prm
|
|||
ViewVelocity,
|
||||
JumpRecover,
|
||||
Buoyancy,
|
||||
FallDamage,
|
||||
VelocityMultiplier,
|
||||
MovementDrag,
|
||||
AngularDrag,
|
||||
RecoverDelay
|
||||
RecoverDelay,
|
||||
FallLimit
|
||||
}
|
||||
|
||||
static public event Action SwitchChange;
|
||||
|
@ -85,6 +87,9 @@ namespace ml_prm
|
|||
ms_uiElements.Add(l_modCategory.AddToggle("Buoyancy", "Enable buoyancy in fluid volumes. Warning: constantly changes movement and air drag of hips, spine and chest.", Settings.Buoyancy));
|
||||
(ms_uiElements[(int)UiIndex.Buoyancy] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate(UiIndex.Buoyancy, state);
|
||||
|
||||
ms_uiElements.Add(l_modCategory.AddToggle("Fall damage", "Enable ragdoll when falling from height", Settings.FallDamage));
|
||||
(ms_uiElements[(int)UiIndex.FallDamage] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => OnToggleUpdate(UiIndex.FallDamage, state);
|
||||
|
||||
ms_uiElements.Add(l_modRoot.AddSlider("Velocity multiplier", "Velocity multiplier upon entering ragdoll state", Settings.VelocityMultiplier, 1f, 50f));
|
||||
(ms_uiElements[(int)UiIndex.VelocityMultiplier] as BTKUILib.UIObjects.Components.SliderFloat).OnValueUpdated += (value) => OnSliderUpdate(UiIndex.VelocityMultiplier, value);
|
||||
|
||||
|
@ -97,6 +102,9 @@ namespace ml_prm
|
|||
ms_uiElements.Add(l_modRoot.AddSlider("Recover delay (seconds)", "Recover delay for automatic recover", Settings.RecoverDelay, 1f, 10f));
|
||||
(ms_uiElements[(int)UiIndex.RecoverDelay] as BTKUILib.UIObjects.Components.SliderFloat).OnValueUpdated += (value) => OnSliderUpdate(UiIndex.RecoverDelay, value);
|
||||
|
||||
ms_uiElements.Add(l_modRoot.AddSlider("Fall limit", "Height limit for fall damage", Settings.FallLimit, 0f, 100f));
|
||||
(ms_uiElements[(int)UiIndex.FallLimit] as BTKUILib.UIObjects.Components.SliderFloat).OnValueUpdated += (value) => OnSliderUpdate(UiIndex.FallLimit, value);
|
||||
|
||||
l_modCategory.AddButton("Reset settings", "", "Reset mod settings to default").OnPress += Reset;
|
||||
}
|
||||
|
||||
|
@ -147,6 +155,10 @@ namespace ml_prm
|
|||
case UiIndex.Buoyancy:
|
||||
Settings.SetSetting(Settings.ModSetting.Buoyancy, p_state);
|
||||
break;
|
||||
|
||||
case UiIndex.FallDamage:
|
||||
Settings.SetSetting(Settings.ModSetting.FallDamage, p_state);
|
||||
break;
|
||||
}
|
||||
|
||||
if(p_force)
|
||||
|
@ -172,6 +184,10 @@ namespace ml_prm
|
|||
case UiIndex.RecoverDelay:
|
||||
Settings.SetSetting(Settings.ModSetting.RecoverDelay, p_value);
|
||||
break;
|
||||
|
||||
case UiIndex.FallLimit:
|
||||
Settings.SetSetting(Settings.ModSetting.FallLimit, p_value);
|
||||
break;
|
||||
}
|
||||
|
||||
if(p_force)
|
||||
|
@ -191,10 +207,12 @@ namespace ml_prm
|
|||
OnToggleUpdate(UiIndex.ViewVelocity, false, true);
|
||||
OnToggleUpdate(UiIndex.JumpRecover, false, true);
|
||||
OnToggleUpdate(UiIndex.Buoyancy, true, true);
|
||||
OnToggleUpdate(UiIndex.FallDamage, true, true);
|
||||
OnSliderUpdate(UiIndex.VelocityMultiplier, 2f, true);
|
||||
OnSliderUpdate(UiIndex.MovementDrag, 1f, true);
|
||||
OnSliderUpdate(UiIndex.AngularDrag, 1f, true);
|
||||
OnSliderUpdate(UiIndex.RecoverDelay, 3f, true);
|
||||
OnSliderUpdate(UiIndex.FallLimit, 5f, true);
|
||||
}
|
||||
|
||||
static Stream GetIconStream(string p_name)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.1.1", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.1.2", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonPriority(2)]
|
||||
[assembly: MelonLoader.MelonOptionalDependencies("BTKUILib")]
|
||||
|
|
|
@ -26,8 +26,9 @@ Optional mod's settings page with [BTKUILib](https://github.com/BTK-Development/
|
|||
* **View direction velocity:** apply velocity to camera view direction instead of player movement direction; `false` by default.
|
||||
* Note: Forcibly disabled in worlds that don't allow flight.
|
||||
* **Jump recover:** enables recovering from ragdoll state by jumping; `false` by default.
|
||||
* **Buoyancy:** enabled floating in fluid volumes; `true` by default.
|
||||
* **Buoyancy:** enables floating in fluid volumes; `true` by default.
|
||||
* Note: Forcibly enabled in worlds that don't allow flight.
|
||||
* **Fall damage:** enables ragdoll when falling from specific height; `true` by default.
|
||||
* **Velocity multiplier:** velocity force multiplier based on player's movement direction; `2.0` by default.
|
||||
* Note: Limited according to world's fly multiplier.
|
||||
* Note: Forcibly set to `1.0` in worlds that don't allow flight.
|
||||
|
@ -35,6 +36,7 @@ Optional mod's settings page with [BTKUILib](https://github.com/BTK-Development/
|
|||
* Note: Forcibly set to `1.0` in worlds that don't allow flight.
|
||||
* **Angular movement drag:** angular movement resistance; `2.0` by default.
|
||||
* **Recover delay:** time delay for enabled `Auto recover` in seconds; `3.0` by default.
|
||||
* **Fall limit:** height limit for fall damage; `5.0` by default.
|
||||
* **Reset settings:** resets mod settings to default.
|
||||
|
||||
Optional mod's settings in [UIExpansionKit](https://github.com/ddakebono/ChilloutMods):
|
||||
|
|
|
@ -52,6 +52,9 @@ namespace ml_prm
|
|||
float m_groundedTime = 0f;
|
||||
float m_downTime = float.MinValue;
|
||||
|
||||
bool m_inAir = false;
|
||||
float m_inAirDistance = 0f;
|
||||
|
||||
internal RagdollController()
|
||||
{
|
||||
m_rigidBodies = new List<Rigidbody>();
|
||||
|
@ -88,6 +91,7 @@ namespace ml_prm
|
|||
Settings.SlipperinessChange += this.OnPhysicsMaterialChange;
|
||||
Settings.BouncinessChange += this.OnPhysicsMaterialChange;
|
||||
Settings.BuoyancyChange += this.OnBuoyancyChange;
|
||||
Settings.FallDamageChange += this.OnFallDamageChange;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
|
@ -124,12 +128,29 @@ namespace ml_prm
|
|||
Settings.SlipperinessChange -= this.OnPhysicsMaterialChange;
|
||||
Settings.BouncinessChange -= this.OnPhysicsMaterialChange;
|
||||
Settings.BuoyancyChange -= this.OnBuoyancyChange;
|
||||
Settings.FallDamageChange -= this.OnFallDamageChange;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(m_avatarReady && !m_enabled && Settings.FallDamage && !MovementSystem.Instance.flying)
|
||||
{
|
||||
bool l_grounded = MovementSystem.Instance.IsGroundedRaw();
|
||||
if(m_inAir && l_grounded && (m_inAirDistance > Settings.FallLimit))
|
||||
{
|
||||
m_inAirDistance = 0f;
|
||||
SwitchRagdoll();
|
||||
}
|
||||
|
||||
m_inAir = !l_grounded;
|
||||
if(l_grounded)
|
||||
m_inAirDistance = 0f;
|
||||
}
|
||||
|
||||
if(m_avatarReady && m_enabled)
|
||||
{
|
||||
m_inAirDistance = 0f;
|
||||
|
||||
Vector3 l_dif = m_puppetReferences.hips.position - m_ragdollLastPos;
|
||||
PlayerSetup.Instance.transform.position += l_dif;
|
||||
m_puppetReferences.hips.position -= l_dif;
|
||||
|
@ -142,6 +163,12 @@ namespace ml_prm
|
|||
{
|
||||
Vector3 l_pos = PlayerSetup.Instance.transform.position;
|
||||
m_velocity = (m_velocity + (l_pos - m_lastPosition) / Time.deltaTime) * 0.5f;
|
||||
if(m_inAir)
|
||||
{
|
||||
m_inAirDistance += (m_lastPosition - l_pos).y;
|
||||
m_inAirDistance = Mathf.Clamp(m_inAirDistance, 0f, float.MaxValue);
|
||||
}
|
||||
|
||||
m_lastPosition = l_pos;
|
||||
|
||||
if(!m_reachedGround && MovementSystem.Instance.IsGrounded())
|
||||
|
@ -233,6 +260,8 @@ namespace ml_prm
|
|||
m_groundedTime = 0f;
|
||||
m_downTime = float.MinValue;
|
||||
m_puppetRoot.localScale = Vector3.one;
|
||||
m_inAir = false;
|
||||
m_inAirDistance = 0f;
|
||||
}
|
||||
|
||||
internal void OnAvatarSetup()
|
||||
|
@ -410,6 +439,7 @@ namespace ml_prm
|
|||
OnPhysicsMaterialChange(true);
|
||||
OnMovementDragChange(Settings.MovementDrag);
|
||||
OnBuoyancyChange(Settings.Buoyancy);
|
||||
OnFallDamageChange(Settings.FallDamage);
|
||||
}
|
||||
|
||||
internal void OnCombatDown()
|
||||
|
@ -425,6 +455,8 @@ namespace ml_prm
|
|||
|
||||
internal void OnChangeFlight()
|
||||
{
|
||||
OnFallDamageChange(Settings.FallDamage);
|
||||
|
||||
if(m_avatarReady && m_enabled && MovementSystem.Instance.flying)
|
||||
{
|
||||
m_forcedSwitch = true;
|
||||
|
@ -435,6 +467,8 @@ namespace ml_prm
|
|||
|
||||
internal void OnPlayerTeleport()
|
||||
{
|
||||
OnFallDamageChange(Settings.FallDamage);
|
||||
|
||||
if(m_avatarReady && m_enabled)
|
||||
m_ragdollLastPos = m_puppetReferences.hips.position;
|
||||
}
|
||||
|
@ -530,6 +564,11 @@ namespace ml_prm
|
|||
}
|
||||
}
|
||||
}
|
||||
void OnFallDamageChange(bool p_state)
|
||||
{
|
||||
m_inAir = false;
|
||||
m_inAirDistance = 0f;
|
||||
}
|
||||
|
||||
// Arbitrary
|
||||
public void SwitchRagdoll()
|
||||
|
|
|
@ -23,7 +23,9 @@ namespace ml_prm
|
|||
Bounciness,
|
||||
ViewVelocity,
|
||||
JumpRecover,
|
||||
Buoyancy
|
||||
Buoyancy,
|
||||
FallDamage,
|
||||
FallLimit
|
||||
}
|
||||
|
||||
public static bool Hotkey { get; private set; } = true;
|
||||
|
@ -42,6 +44,8 @@ namespace ml_prm
|
|||
public static bool ViewVelocity { get; private set; } = false;
|
||||
public static bool JumpRecover { get; private set; } = false;
|
||||
public static bool Buoyancy { get; private set; } = true;
|
||||
public static bool FallDamage { get; private set; } = true;
|
||||
public static float FallLimit { get; private set; } = 5f;
|
||||
|
||||
static public event Action<bool> HotkeyChange;
|
||||
static public event Action<KeyCode> HotkeyKeyChange;
|
||||
|
@ -59,6 +63,8 @@ namespace ml_prm
|
|||
static public event Action<bool> ViewVelocityChange;
|
||||
static public event Action<bool> JumpRecoverChange;
|
||||
static public event Action<bool> BuoyancyChange;
|
||||
static public event Action<bool> FallDamageChange;
|
||||
static public event Action<float> FallLimitChange;
|
||||
|
||||
static MelonLoader.MelonPreferences_Category ms_category = null;
|
||||
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
||||
|
@ -85,6 +91,8 @@ namespace ml_prm
|
|||
ms_category.CreateEntry(ModSetting.ViewVelocity.ToString(), ViewVelocity, null, null, true),
|
||||
ms_category.CreateEntry(ModSetting.JumpRecover.ToString(), JumpRecover, null, null, true),
|
||||
ms_category.CreateEntry(ModSetting.Buoyancy.ToString(), Buoyancy, null, null, true),
|
||||
ms_category.CreateEntry(ModSetting.FallDamage.ToString(), FallDamage, null, null, true),
|
||||
ms_category.CreateEntry(ModSetting.FallLimit.ToString(), FallLimit, null, null, true),
|
||||
};
|
||||
|
||||
ms_entries[(int)ModSetting.HotkeyKey].OnEntryValueChangedUntyped.Subscribe(OnMelonSettingSave_HotkeyKey);
|
||||
|
@ -105,6 +113,8 @@ namespace ml_prm
|
|||
ViewVelocity = (bool)ms_entries[(int)ModSetting.ViewVelocity].BoxedValue;
|
||||
JumpRecover = (bool)ms_entries[(int)ModSetting.JumpRecover].BoxedValue;
|
||||
Buoyancy = (bool)ms_entries[(int)ModSetting.Buoyancy].BoxedValue;
|
||||
FallDamage = (bool)ms_entries[(int)ModSetting.FallDamage].BoxedValue;
|
||||
FallLimit = Mathf.Clamp((float)ms_entries[(int)ModSetting.FallLimit].BoxedValue, 0f, 100f);
|
||||
}
|
||||
|
||||
static void OnMelonSettingSave_HotkeyKey(object p_oldValue, object p_newValue)
|
||||
|
@ -198,6 +208,13 @@ namespace ml_prm
|
|||
}
|
||||
break;
|
||||
|
||||
case ModSetting.FallDamage:
|
||||
{
|
||||
FallDamage = (bool)p_value;
|
||||
FallDamageChange?.Invoke((bool)p_value);
|
||||
}
|
||||
break;
|
||||
|
||||
// Floats
|
||||
case ModSetting.VelocityMultiplier:
|
||||
{
|
||||
|
@ -226,6 +243,13 @@ namespace ml_prm
|
|||
RecoverDelayChange?.Invoke((float)p_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case ModSetting.FallLimit:
|
||||
{
|
||||
FallLimit = (float)p_value;
|
||||
FallLimitChange?.Invoke((float)p_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(ms_entries != null)
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace ml_prm
|
|||
return l_result;
|
||||
}
|
||||
|
||||
public static bool IsGrounded(this MovementSystem p_instance) => (bool)ms_groundedRaw.GetValue(p_instance);
|
||||
public static bool IsGroundedRaw(this MovementSystem p_instance) => (bool)ms_groundedRaw.GetValue(p_instance);
|
||||
public static Vector3 GetAppliedGravity(this MovementSystem p_instance) => (Vector3)ms_appliedGravity.GetValue(p_instance);
|
||||
public static void SetAppliedGravity(this MovementSystem p_instance, Vector3 p_vec) => ms_appliedGravity.SetValue(p_instance, p_vec);
|
||||
public static void ClearFluidVolumes(this MovementSystem p_instance) => (ms_touchingVolumes.GetValue(p_instance) as List<FluidVolume>)?.Clear();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<PackageId>PlayerRagdollMod</PackageId>
|
||||
<Version>1.1.1</Version>
|
||||
<Version>1.1.2</Version>
|
||||
<Authors>SDraw</Authors>
|
||||
<Company>None</Company>
|
||||
<Product>PlayerRagdollMod</Product>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue