mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Alternative collider scale
This commit is contained in:
parent
027e6c29cd
commit
25969abef9
7 changed files with 103 additions and 6 deletions
|
@ -2,6 +2,8 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.IK.SubSystems;
|
||||
using System.Reflection;
|
||||
using ABI_RC.Systems.MovementSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_amt
|
||||
{
|
||||
|
@ -59,6 +61,13 @@ namespace ml_amt
|
|||
);
|
||||
}
|
||||
|
||||
// Alternative collider height
|
||||
HarmonyInstance.Patch(
|
||||
typeof(MovementSystem).GetMethod("UpdateCollider", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnUpdateCollider_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
null
|
||||
);
|
||||
|
||||
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
||||
}
|
||||
|
||||
|
@ -149,5 +158,64 @@ namespace ml_amt
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Alternative collider size
|
||||
static bool OnUpdateCollider_Prefix(
|
||||
ref MovementSystem __instance,
|
||||
bool __0, // updateRadius
|
||||
CharacterController ___controller,
|
||||
float ____avatarHeight,
|
||||
float ____avatarHeightFactor,
|
||||
float ____minimumColliderRadius,
|
||||
Vector3 ____colliderCenter
|
||||
)
|
||||
{
|
||||
if(!Settings.CollisionScale)
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
if(___controller != null)
|
||||
{
|
||||
float l_scaledHeight = ____avatarHeight * ____avatarHeightFactor;
|
||||
float l_newRadius = (__0 ? Mathf.Max(____minimumColliderRadius, l_scaledHeight / 6f) : ___controller.radius);
|
||||
|
||||
float l_newHeight = Mathf.Max(l_scaledHeight, l_newRadius * 2f);
|
||||
float l_currentHeight = ___controller.height;
|
||||
|
||||
Vector3 l_newCenter = ____colliderCenter;
|
||||
l_newCenter.y = (l_newHeight + 0.075f * ____avatarHeightFactor) * 0.5f;
|
||||
Vector3 l_currentCenter = ___controller.center;
|
||||
|
||||
if((Mathf.Abs(l_currentHeight - l_newHeight) > (l_currentHeight * 0.05f)) || (Vector3.Distance(l_currentCenter,l_newCenter) > (l_currentHeight * 0.05f)))
|
||||
{
|
||||
bool l_active = ___controller.enabled;
|
||||
|
||||
if(__0)
|
||||
___controller.radius = l_newRadius;
|
||||
___controller.height = l_newHeight;
|
||||
___controller.center = l_newCenter;
|
||||
|
||||
__instance.groundDistance = l_newRadius;
|
||||
|
||||
if(__0)
|
||||
__instance.proxyCollider.radius = l_newRadius;
|
||||
__instance.proxyCollider.height = l_newHeight;
|
||||
__instance.proxyCollider.center = new Vector3(0f, l_newCenter.y, 0f);
|
||||
|
||||
__instance.forceObject.transform.localScale = new Vector3(l_newRadius + 0.1f, l_newHeight, l_newRadius + 0.1f);
|
||||
__instance.groundCheck.localPosition = ____colliderCenter;
|
||||
|
||||
___controller.enabled = l_active;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(System.Exception l_exception)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(l_exception);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle("AvatarMotionTweaker")]
|
||||
[assembly: AssemblyVersion("1.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.0")]
|
||||
[assembly: AssemblyVersion("1.2.1")]
|
||||
[assembly: AssemblyFileVersion("1.2.1")]
|
||||
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_amt.AvatarMotionTweaker), "AvatarMotionTweaker", "1.2.1", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
|
@ -22,8 +22,9 @@ Available mod's settings in `Settings - IK - Avatar Motion Tweaker`:
|
|||
* **Pose transitions:** allows regular avatars animator to transit in crouch/prone states; default value - `true`.
|
||||
* Note: Avatar is considered as regular if its AAS animator doesn't have `Upright` parameter.
|
||||
* **Adjusted pose movement speed:** scales movement speed upon crouching/proning; default value - `true`.
|
||||
* **Detect animations emote tag:** disables avatar's IK entirely if current animator state has `Emote` tag; default value - `true`;
|
||||
* **Detect animations emote tag:** disables avatar's IK entirely if current animator state has `Emote` tag; default value - `true`.
|
||||
* Note: Created as example for [propoused game feature](https://feedback.abinteractive.net/p/disabling-vr-ik-for-emotes-via-animator-state-tag-7b80d963-053a-41c0-86ac-e3d53c61c1e2).
|
||||
* **Alternative avatar collider scale:** applies slightly different approach to avatar collider size change; default value - `true`
|
||||
|
||||
Available additional parameters for AAS animator:
|
||||
* **`Upright`:** defines linear coefficient between current viewpoint height and avatar's viewpoint height; float, range - [0.0, 1.0].
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace ml_amt
|
|||
IKOverrideFly,
|
||||
IKOverrideJump,
|
||||
DetectEmotes,
|
||||
FollowHips
|
||||
FollowHips,
|
||||
CollisionScale
|
||||
};
|
||||
|
||||
static bool ms_ikOverrideCrouch = true;
|
||||
|
@ -31,6 +32,7 @@ namespace ml_amt
|
|||
static bool ms_ikOverrideJump = true;
|
||||
static bool ms_detectEmotes = true;
|
||||
static bool ms_followHips = true;
|
||||
static bool ms_collisionScale = true;
|
||||
|
||||
static MelonLoader.MelonPreferences_Category ms_category = null;
|
||||
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
||||
|
@ -45,6 +47,7 @@ namespace ml_amt
|
|||
static public event Action<bool> IKOverrideJumpChange;
|
||||
static public event Action<bool> DetectEmotesChange;
|
||||
static public event Action<bool> FollowHipsChange;
|
||||
static public event Action<bool> CollisionScaleChange;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
|
@ -61,6 +64,7 @@ namespace ml_amt
|
|||
ms_entries.Add(ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), true));
|
||||
ms_entries.Add(ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), true));
|
||||
ms_entries.Add(ms_category.CreateEntry(ModSetting.FollowHips.ToString(), true));
|
||||
ms_entries.Add(ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), true));
|
||||
|
||||
Load();
|
||||
|
||||
|
@ -101,6 +105,7 @@ namespace ml_amt
|
|||
ms_ikOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue;
|
||||
ms_detectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue;
|
||||
ms_followHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue;
|
||||
ms_collisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue;
|
||||
}
|
||||
|
||||
static void OnSliderUpdate(string p_name, string p_value)
|
||||
|
@ -189,6 +194,13 @@ namespace ml_amt
|
|||
FollowHipsChange?.Invoke(ms_followHips);
|
||||
}
|
||||
break;
|
||||
|
||||
case ModSetting.CollisionScale:
|
||||
{
|
||||
ms_collisionScale = bool.Parse(p_value);
|
||||
CollisionScaleChange?.Invoke(ms_collisionScale);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);
|
||||
|
@ -235,5 +247,9 @@ namespace ml_amt
|
|||
{
|
||||
get => ms_followHips;
|
||||
}
|
||||
public static bool CollisionScale
|
||||
{
|
||||
get => ms_collisionScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,11 @@
|
|||
<Reference Include="UnityEngine.CoreModule">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>D:\Games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MotionTweaker.cs" />
|
||||
|
|
|
@ -249,6 +249,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
|
|||
<div id="DetectEmotes" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class ="row-wrapper">
|
||||
<div class ="option-caption">Alternative avatar collider scale: </div>
|
||||
<div class ="option-input">
|
||||
<div id="CollisionScale" class ="inp_toggle no-scroll" data-current="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('settings-ik').appendChild(l_block);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue