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

Track body position and rotation, show feet #22

Merged
merged 37 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
260bc5f
Manually set camera position
Raicuparta Nov 20, 2021
9157f80
Fix UnityHelper dependency
Raicuparta Nov 20, 2021
0527a73
Moving too much
Raicuparta Nov 20, 2021
7cdc4fa
for some reason following the cube works
Raicuparta Nov 20, 2021
8bf519c
So close
Raicuparta Nov 20, 2021
661c4b4
not quite
Raicuparta Nov 20, 2021
6124140
Ugh
Raicuparta Nov 20, 2021
6680844
add another camera wrapper
Raicuparta Nov 20, 2021
caccecc
ok?
Raicuparta Nov 20, 2021
b62a388
Revert camera offset parent
Raicuparta Nov 20, 2021
6b39c95
Make shoes visible
Raicuparta Nov 20, 2021
920121f
Prevent smol
Raicuparta Nov 20, 2021
a63be0d
keep player grounded
Raicuparta Nov 20, 2021
0b2c43a
prevent flying
Raicuparta Nov 20, 2021
734c928
Cleanup
Raicuparta Nov 20, 2021
e337a67
Better move
Raicuparta Nov 20, 2021
74267ff
Smooth bruv
Raicuparta Nov 20, 2021
5bd7843
ignore camera rotation while moving
Raicuparta Nov 20, 2021
433f512
rotating but oof
Raicuparta Nov 20, 2021
507d594
No need to manually set position I think
Raicuparta Nov 20, 2021
0439ba6
smooth??
Raicuparta Nov 20, 2021
3461296
better I think
Raicuparta Nov 20, 2021
0c453e3
shaky but ok
Raicuparta Nov 20, 2021
f280ab2
Better
Raicuparta Nov 20, 2021
402a242
Cleanup
Raicuparta Nov 20, 2021
d5f0cb4
Prevent moving while navigation controller disabled
Raicuparta Nov 20, 2021
e81d947
Remove threshold
Raicuparta Nov 25, 2021
979ede0
somehow this seems to work
Raicuparta Nov 25, 2021
32ab045
Prevent rotating during animations
Raicuparta Nov 25, 2021
9f829e7
Fix rotation delay, make rotation instant
Raicuparta Nov 25, 2021
9f39ca1
Add todo
Raicuparta Nov 25, 2021
b7030e7
Prevent recentering vertically after rotate
Raicuparta Nov 26, 2021
c8ec2e6
Remove obsolete comment
Raicuparta Nov 27, 2021
118c107
Remove redundant dontdestroyonload
Raicuparta Nov 27, 2021
288054a
Prevent camera rotation limits from changing
Raicuparta Nov 27, 2021
b689c86
Fix initial recenter not recentering vertically
Raicuparta Nov 27, 2021
4c158cd
Cleanup
Raicuparta Nov 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions TwoForksVR/TwoForksVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<OutputPath>C:\Program Files (x86)\GOG Galaxy\Games\Firewatch\BepInEx\plugins</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -87,7 +87,7 @@
<Private>False</Private>
</Reference>
<Reference Include="UnityHelper, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\UnityHelper\obj\Debug\UnityHelper.dll</HintPath>
<HintPath>..\UnityHelper\obj\Release\UnityHelper.dll</HintPath>
</Reference>
<Reference Include="Valve.Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\UnityHelper\Assets\SteamVR\Input\Plugins\JSON.NET\Valve.Newtonsoft.Json.dll</HintPath>
Expand All @@ -112,6 +112,7 @@
<Compile Include="src\Input\Patches\MousePatches.cs" />
<Compile Include="src\Input\VrAxisData.cs" />
<Compile Include="src\PlayerBody\Patches\BodyPatches.cs" />
<Compile Include="src\PlayerBody\Patches\NavigationPatches.cs" />
<Compile Include="src\PlayerBody\VRBodyManager.cs" />
<Compile Include="src\PlayerCamera\Patches\CameraTransformProtectionPatches.cs" />
<Compile Include="src\PlayerCamera\Patches\GameCameraPatches.cs" />
Expand Down Expand Up @@ -183,6 +184,9 @@
</None>
</ItemGroup>
<ItemGroup>
<Content Include="TwoForksVrAssets\AssetBundles\body">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="TwoForksVrAssets\AssetBundles\hand">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Binary file not shown.
17 changes: 17 additions & 0 deletions TwoForksVR/TwoForksVrAssets/AssetBundles/AssetBundles.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ManifestFileVersion: 0
CRC: 755994654
AssetBundleManifest:
AssetBundleInfos:
Info_0:
Name: hand
Dependencies: {}
Info_1:
Name: hands
Dependencies: {}
Info_2:
Name: tool-picker
Dependencies:
Dependency_0: hand
Info_3:
Name: body
Dependencies: {}
Binary file added TwoForksVR/TwoForksVrAssets/AssetBundles/body
Binary file not shown.
31 changes: 31 additions & 0 deletions TwoForksVR/TwoForksVrAssets/AssetBundles/body.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ManifestFileVersion: 0
CRC: 3146153261
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: 658595ebc75709d071ec3b0165f784eb
TypeTreeHash:
serializedVersion: 2
Hash: c779f9c875c9ee4bb1858a77951478a2
HashAppended: 0
ClassTypes:
- Class: 1
Script: {instanceID: 0}
- Class: 4
Script: {instanceID: 0}
- Class: 21
Script: {instanceID: 0}
- Class: 23
Script: {instanceID: 0}
- Class: 28
Script: {instanceID: 0}
- Class: 33
Script: {instanceID: 0}
- Class: 43
Script: {instanceID: 0}
- Class: 48
Script: {instanceID: 0}
Assets:
- Assets/Prefabs/ShoeLid.prefab
- Assets/Textures/body-cutout.png
Dependencies: []
42 changes: 42 additions & 0 deletions TwoForksVR/TwoForksVrAssets/AssetBundles/hand.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ManifestFileVersion: 0
CRC: 1128861655
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: d743bf55bf70beb15a0a3ce5ad5c06d7
TypeTreeHash:
serializedVersion: 2
Hash: 9eb0905dc6a6a3e5b1a097f997ac7512
HashAppended: 0
ClassTypes:
- Class: 1
Script: {instanceID: 0}
- Class: 4
Script: {instanceID: 0}
- Class: 21
Script: {instanceID: 0}
- Class: 23
Script: {instanceID: 0}
- Class: 28
Script: {instanceID: 0}
- Class: 33
Script: {instanceID: 0}
- Class: 43
Script: {instanceID: 0}
- Class: 48
Script: {instanceID: 0}
- Class: 114
Script: {fileID: 11500000, guid: 9a5fb0ca93b55ef4b8d54b512b103341, type: 3}
- Class: 115
Script: {instanceID: 0}
- Class: 213
Script: {instanceID: 0}
Assets:
- Assets/Prefabs/Hand.prefab
- Assets/Sprites/Icons/compass.png
- Assets/Sprites/Icons/map.png
- Assets/Sprites/Icons/radio.png
- Assets/Sprites/Icons/flashlight.png
- Assets/Textures/arms-cutout.png
- Assets/Prefabs/HandLid.prefab
Dependencies: []
28 changes: 28 additions & 0 deletions TwoForksVR/TwoForksVrAssets/AssetBundles/hands.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ManifestFileVersion: 0
CRC: 4219293831
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: 639c2ccbe561e7284c69392923fb84fa
TypeTreeHash:
serializedVersion: 2
Hash: cabdba1f47cfa18d989066811dbb64a2
HashAppended: 0
ClassTypes:
- Class: 1
Script: {instanceID: 0}
- Class: 4
Script: {instanceID: 0}
- Class: 21
Script: {instanceID: 0}
- Class: 23
Script: {instanceID: 0}
- Class: 33
Script: {instanceID: 0}
- Class: 43
Script: {instanceID: 0}
- Class: 48
Script: {instanceID: 0}
Assets:
- Assets/Prefabs/VRHands.prefab
Dependencies: []
29 changes: 29 additions & 0 deletions TwoForksVR/TwoForksVrAssets/AssetBundles/tool-picker.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ManifestFileVersion: 0
CRC: 1220775659
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: b829325390256577cefd963fea17dd91
TypeTreeHash:
serializedVersion: 2
Hash: 8c82af9f276b27ec2a396fecb7931109
HashAppended: 0
ClassTypes:
- Class: 1
Script: {instanceID: 0}
- Class: 4
Script: {instanceID: 0}
- Class: 21
Script: {instanceID: 0}
- Class: 28
Script: {instanceID: 0}
- Class: 48
Script: {instanceID: 0}
- Class: 212
Script: {instanceID: 0}
- Class: 213
Script: {instanceID: 0}
Assets:
- Assets/Prefabs/ToolPicker.prefab
Dependencies:
- C:/Users/rai/Repos/two-forks-vr/UnityHelper/../TwoForksVr/TwoForksVrAssets/AssetBundles/hand
5 changes: 5 additions & 0 deletions TwoForksVR/src/Assets/VRAssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ public static class VRAssetLoader
private const string assetsDir = "/BepInEx/plugins/TwoForksVrAssets/AssetBundles/";
public static GameObject ToolPicker { get; private set; }
public static GameObject HandLid { get; private set; }
public static GameObject ShoeLid { get; private set; }
public static Texture2D ArmsCutoutTexture { get; private set; }
public static Texture2D BodyCutoutTexture { get; private set; }
public static GameObject Hands { get; private set; }

public static void LoadAssets()
{
var handAsset = LoadBundle("hand");
var bodyAsset = LoadBundle("body");
HandLid = handAsset.LoadAsset<GameObject>("HandLid");
ShoeLid = bodyAsset.LoadAsset<GameObject>("ShoeLid");
ArmsCutoutTexture = handAsset.LoadAsset<Texture2D>("arms-cutout");
BodyCutoutTexture = bodyAsset.LoadAsset<Texture2D>("body-cutout");
ToolPicker = LoadAssetPrefab("tool-picker", "ToolPicker");
Hands = LoadAssetPrefab("hands", "VRHands");
}
Expand Down
31 changes: 23 additions & 8 deletions TwoForksVR/src/Hands/VRHand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class VRHand : MonoBehaviour
private GameObject fallbackHandModel;
private string handName;
private bool isLeft;
private Transform rootBone;
// private Transform rootBone;

private void Start()
{
Expand All @@ -33,11 +33,10 @@ public static VRHand Create(Transform parent, bool isLeft = false)
public void SetUp(Transform playerRootBone)
{
gameObject.SetActive(false);
rootBone = playerRootBone;
if (playerRootBone)
{
SetFallbackHandActive(false);
EnableAnimatedHand();
EnableAnimatedHand(playerRootBone);
}
else
{
Expand Down Expand Up @@ -68,19 +67,20 @@ private void SetFallbackHandActive(bool active)
fallbackHandModel.SetActive(active);
}

private void EnableAnimatedHand()
private void EnableAnimatedHand(Transform playerRootBone)
{
if (!rootBone) return;
if (!playerRootBone) return;

var armBone = SetUpArmBone();
var armBone = SetUpArmBone(playerRootBone);
SetUpHandLid(armBone);
SetUpHandBone(armBone);
SetUpShoeLid(playerRootBone);
}

private Transform SetUpArmBone()
private Transform SetUpArmBone(Transform playerRootBone)
{
var armBone =
rootBone.Find(
playerRootBone.Find(
$"henryPelvis/henrySpineA/henrySpineB/henrySpineC/henrySpineD/henrySpider{handName}1/henrySpider{handName}2/henrySpider{handName}IK/henryArm{handName}Collarbone/henryArm{handName}1/henryArm{handName}2");
var updateFollow = armBone.GetComponent<LateUpdateFollow>() ??
armBone.gameObject.AddComponent<LateUpdateFollow>();
Expand All @@ -95,6 +95,21 @@ private void SetUpHandLid(Transform armBone)
handLid.SetParent(armBone, false);
if (isLeft) handLid.localScale = new Vector3(1, 1, -1);
}

private void SetUpShoeLid(Transform playerRootBone)
{
var shoeBone = playerRootBone.Find(
$"henryPelvis/henryHips/henryLeg{handName}1/henryLeg{handName}2/henryLeg{handName}Foot");
if (!shoeBone)
{
Logs.LogError("### could not find shoe bone");
return;
}
var handLid = Instantiate(VRAssetLoader.ShoeLid).transform;
handLid.Find("ShoeLidModel").gameObject.layer = LayerMask.NameToLayer("UI");
handLid.SetParent(shoeBone, false);
if (isLeft) handLid.localScale = new Vector3(1, 1, -1);
}

private void SetUpHandBone(Transform armBone)
{
Expand Down
34 changes: 3 additions & 31 deletions TwoForksVR/src/Helpers/Logs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,19 @@ namespace TwoForksVr.Helpers
{
public static class Logs
{
private static void OnUnityLog(string condition, string stackTrace, LogType type)
{
// if (type == LogType.Log) return;
switch (type)
{
case LogType.Exception:
case LogType.Error:
{
LogError(condition);
if (!string.IsNullOrEmpty(stackTrace)) LogError($"error stack trace: [[ {stackTrace} ]]");
return;
}
case LogType.Warning:
{
LogWarning(condition);
if (!string.IsNullOrEmpty(stackTrace))
LogWarning($"warning stack trace: [[ {stackTrace} ]]");
return;
}
default:
{
LogInfo($"{type}: {condition}");
if (!string.IsNullOrEmpty(stackTrace)) LogError($"log stack trace: [[ {stackTrace} ]]");
return;
}
}
}

public static void LogInfo(object data)
{
UnityEngine.Debug.Log(data);
Debug.Log(data);
}

public static void LogWarning(object data)
{
UnityEngine.Debug.LogWarning(data);
Debug.LogWarning(data);
}

public static void LogError(object data)
{
UnityEngine.Debug.LogError(data);
Debug.LogError(data);
}
}
}
2 changes: 1 addition & 1 deletion TwoForksVR/src/Input/Patches/MousePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class MousePatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(vgCursorManager), nameof(vgCursorManager.Awake))]
private static bool PatchCursorManager(vgCursorManager __instance)
private static bool DestroyCursorManager(vgCursorManager __instance)
{
Object.Destroy(__instance);
return false;
Expand Down
4 changes: 2 additions & 2 deletions TwoForksVR/src/PlayerBody/Patches/BodyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace TwoForksVr.PlayerBody.Patches
{
[HarmonyPatch]
public class BodyPatches
public static class BodyPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(vgPlayerController), nameof(vgPlayerController.Awake))]
public static void CreateBodyManager(vgPlayerController __instance)
{
VRBodyManager.Create(__instance.transform);
VRBodyManager.Create(__instance);
}

[HarmonyPrefix]
Expand Down
37 changes: 37 additions & 0 deletions TwoForksVR/src/PlayerBody/Patches/NavigationPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HarmonyLib;
using UnityEngine;

namespace TwoForksVr.PlayerBody.Patches
{
[HarmonyPatch]
public static class NavigationPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(vgPlayerNavigationController), nameof(vgPlayerNavigationController.Start))]
public static void CreateBodyManager(vgPlayerNavigationController __instance)
{
// Usually NavigationController uses player camera forward as a basis for movement direction.
// This dummy camera is used instead, so that NavigationController now only uses the player body direction.
var dummyCamera = new GameObject("ForwardFacingDummyCamera").AddComponent<Camera>();
dummyCamera.transform.SetParent(__instance.transform, false);
dummyCamera.enabled = false;
__instance.playerCamera = dummyCamera;

__instance.playerRotationSpringConstant = 0;
__instance.playerRotationDamping = 0;
__instance.largestAllowedYawDelta = 0;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(vgPlayerNavigationController), nameof(vgPlayerNavigationController.Start))]
public static void MakeRotationInstant(vgPlayerNavigationController __instance)
{
// Player rotation has some acceleration which does't feel nice in VR.
// Plus it affects some of the hacks I'm doing to rotate the player based on headset rotation.
// This disables any acceleration and makes rotation instant.
__instance.playerRotationSpringConstant = 0;
__instance.playerRotationDamping = 0;
__instance.largestAllowedYawDelta = 0;
}
}
}
Loading