From 01e0890f10ea75e439e61076ac91c728bf03d856 Mon Sep 17 00:00:00 2001 From: Brian Lindenhof Date: Fri, 18 Oct 2024 16:24:09 +0200 Subject: [PATCH 1/5] Initial VR support --- .sbproj | 3 +- .../gameplay/putter/materials/putter.vmat | 47 ++++ .../gameplay/putter/materials/putter_AO.png | 3 + .../putter/materials/putter_Color.png | 3 + .../putter/materials/putter_Emissive.png | 3 + .../putter/materials/putter_Height.png | 3 + .../putter/materials/putter_Metal.png | 3 + .../putter/materials/putter_Normal.png | 3 + .../putter/materials/putter_Opacity.png | 3 + .../putter/materials/putter_Rough.png | 3 + .../gameplay/putter/materials/putter_mask.png | 3 + .../gameplay/putter/minigolf_putter.vanmgrph | 255 ++++++++++++++++++ Assets/models/gameplay/putter/putter.fbx | 3 + Assets/models/gameplay/putter/putter.vmdl | 134 +++++++++ Assets/models/headset/headset.fbx | 3 + Assets/models/headset/headset.vmdl | 51 ++++ Assets/models/headset/materials/headset.vmat | 42 +++ .../models/headset/materials/headset_AO.png | 3 + .../headset/materials/headset_Color.png | 3 + .../headset/materials/headset_Metal.png | 3 + .../headset/materials/headset_Normal.png | 3 + .../headset/materials/headset_Rough.png | 3 + Assets/prefabs/vrplayer.prefab | 188 +++++++++++++ Code/Ball/VRGolfPlayer.cs | 206 ++++++++++++++ Code/GameLoop/GameManager.cs | 6 + 25 files changed, 979 insertions(+), 1 deletion(-) create mode 100644 Assets/models/gameplay/putter/materials/putter.vmat create mode 100644 Assets/models/gameplay/putter/materials/putter_AO.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Color.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Emissive.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Height.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Metal.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Normal.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Opacity.png create mode 100644 Assets/models/gameplay/putter/materials/putter_Rough.png create mode 100644 Assets/models/gameplay/putter/materials/putter_mask.png create mode 100644 Assets/models/gameplay/putter/minigolf_putter.vanmgrph create mode 100644 Assets/models/gameplay/putter/putter.fbx create mode 100644 Assets/models/gameplay/putter/putter.vmdl create mode 100644 Assets/models/headset/headset.fbx create mode 100644 Assets/models/headset/headset.vmdl create mode 100644 Assets/models/headset/materials/headset.vmat create mode 100644 Assets/models/headset/materials/headset_AO.png create mode 100644 Assets/models/headset/materials/headset_Color.png create mode 100644 Assets/models/headset/materials/headset_Metal.png create mode 100644 Assets/models/headset/materials/headset_Normal.png create mode 100644 Assets/models/headset/materials/headset_Rough.png create mode 100644 Assets/prefabs/vrplayer.prefab create mode 100644 Code/Ball/VRGolfPlayer.cs diff --git a/.sbproj b/.sbproj index 29819e0..9d361a0 100644 --- a/.sbproj +++ b/.sbproj @@ -24,7 +24,8 @@ "MaxPlayers": 8, "GameCategory": "Sports", "ControlModes": { - "Keyboard": true + "Keyboard": true, + "VR": true }, "CsProjName": "", "Summary": "\u26F3 Play competitive multiplayer Minigolf with your friends.", diff --git a/Assets/models/gameplay/putter/materials/putter.vmat b/Assets/models/gameplay/putter/materials/putter.vmat new file mode 100644 index 0000000..4c8337e --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter.vmat @@ -0,0 +1,47 @@ +// THIS FILE IS AUTO-GENERATED + +Layer0 +{ + shader "shaders/complex.shader" + + //---- Color ---- + F_TINT_MASK 1 + + //---- PBR ---- + F_METALNESS_TEXTURE 1 + F_SPECULAR 1 + + //---- Ambient Occlusion ---- + g_flAmbientOcclusionDirectDiffuse "0.000" + g_flAmbientOcclusionDirectSpecular "0.000" + TextureAmbientOcclusion "models/gameplay/putter/materials/putter_ao.png" + + //---- Color ---- + g_flModelTintAmount "1.000" + g_vColorTint "[1.000000 1.000000 1.000000 0.000000]" + TextureColor "models/gameplay/putter/materials/putter_color.png" + TextureTintMask "models/gameplay/putter/materials/putter_mask.png" + + //---- Fade ---- + g_flFadeExponent "1.000" + + //---- Fog ---- + g_bFogEnabled "1" + + //---- Metalness ---- + TextureMetalness "models/gameplay/putter/materials/putter_metal.png" + + //---- Normal ---- + TextureNormal "models/gameplay/putter/materials/putter_normal.png" + + //---- Roughness ---- + g_flRoughnessScaleFactor "1.000" + TextureRoughness "models/gameplay/putter/materials/putter_rough.png" + + //---- Texture Coordinates ---- + g_nScaleTexCoordUByModelScaleAxis "0" + g_nScaleTexCoordVByModelScaleAxis "0" + g_vTexCoordOffset "[0.000 0.000]" + g_vTexCoordScale "[1.000 1.000]" + g_vTexCoordScrollSpeed "[0.000 0.000]" +} \ No newline at end of file diff --git a/Assets/models/gameplay/putter/materials/putter_AO.png b/Assets/models/gameplay/putter/materials/putter_AO.png new file mode 100644 index 0000000..49cd583 --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_AO.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aee10302a6b2428131421d98005b4822240445104fcce7ed615598847336db2c +size 245808 diff --git a/Assets/models/gameplay/putter/materials/putter_Color.png b/Assets/models/gameplay/putter/materials/putter_Color.png new file mode 100644 index 0000000..c8b5901 --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:752eed52f12b4c5696ad3141951194e254570e90fa062deddbfafd3bf32fe573 +size 362414 diff --git a/Assets/models/gameplay/putter/materials/putter_Emissive.png b/Assets/models/gameplay/putter/materials/putter_Emissive.png new file mode 100644 index 0000000..0aadd8e --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Emissive.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55304dc7e2d48c5aca2b8c7bab9c2318a256dee8888f1279fd8627b01e29a825 +size 3150 diff --git a/Assets/models/gameplay/putter/materials/putter_Height.png b/Assets/models/gameplay/putter/materials/putter_Height.png new file mode 100644 index 0000000..51af9cb --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Height.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:012946a3cc602ee815ee3b41d9b985a2b1ab9aca54d60ce44f5b5b6194eb9020 +size 98027 diff --git a/Assets/models/gameplay/putter/materials/putter_Metal.png b/Assets/models/gameplay/putter/materials/putter_Metal.png new file mode 100644 index 0000000..35920ca --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Metal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79adb09848d298d214b53dbbc298e1b1de9b385ad481f4d2bc446c74a0a6953d +size 5705 diff --git a/Assets/models/gameplay/putter/materials/putter_Normal.png b/Assets/models/gameplay/putter/materials/putter_Normal.png new file mode 100644 index 0000000..8ac037f --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6c8a7bac8648bf0a02425e05676e357ee4c4bfdfb82ccb881aec861e9350ec4 +size 860223 diff --git a/Assets/models/gameplay/putter/materials/putter_Opacity.png b/Assets/models/gameplay/putter/materials/putter_Opacity.png new file mode 100644 index 0000000..25543da --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Opacity.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25a54374d6ec1b15805e4e18643b0665d45c32c504aa14621cfb0decb6434bd0 +size 3178 diff --git a/Assets/models/gameplay/putter/materials/putter_Rough.png b/Assets/models/gameplay/putter/materials/putter_Rough.png new file mode 100644 index 0000000..13cc659 --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_Rough.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:456dd5c1c776badb5322e505cd850d9a0e966b47409346ef308e7a0519e9ce07 +size 477534 diff --git a/Assets/models/gameplay/putter/materials/putter_mask.png b/Assets/models/gameplay/putter/materials/putter_mask.png new file mode 100644 index 0000000..e3ab88c --- /dev/null +++ b/Assets/models/gameplay/putter/materials/putter_mask.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2915d625da3da18f1da2398d3306cc2fd2f8e7ad0cd523cf05edde489f6e33f8 +size 10343 diff --git a/Assets/models/gameplay/putter/minigolf_putter.vanmgrph b/Assets/models/gameplay/putter/minigolf_putter.vanmgrph new file mode 100644 index 0000000..2aeccd8 --- /dev/null +++ b/Assets/models/gameplay/putter/minigolf_putter.vanmgrph @@ -0,0 +1,255 @@ + +{ + _class = "CAnimationGraph" + m_nodeManager = + { + _class = "CAnimNodeManager" + m_nodes = + [ + { + key = + { + m_id = 6598798 + } + value = + { + _class = "CRootAnimNode" + m_sName = "Unnamed" + m_vecPosition = [ 16.0, -16.0 ] + m_nNodeID = + { + m_id = 6598798 + } + m_sNote = "" + m_inputConnection = + { + m_nodeID = + { + m_id = 1075778687 + } + m_outputID = + { + m_id = 4294967295 + } + } + } + }, + { + key = + { + m_id = 1075778687 + } + value = + { + _class = "CBlendAnimNode" + m_sName = "PutterLength" + m_vecPosition = [ -263.0, -16.0 ] + m_nNodeID = + { + m_id = 1075778687 + } + m_sNote = "" + m_children = + [ + { + m_inputConnection = + { + m_nodeID = + { + m_id = 1233287384 + } + m_outputID = + { + m_id = 4294967295 + } + } + m_name = "60" + m_blendValue = 60.0 + }, + { + m_inputConnection = + { + m_nodeID = + { + m_id = 2066078636 + } + m_outputID = + { + m_id = 4294967295 + } + } + m_name = "72.5" + m_blendValue = 72.5 + }, + { + m_inputConnection = + { + m_nodeID = + { + m_id = 1100900612 + } + m_outputID = + { + m_id = 4294967295 + } + } + m_name = "90" + m_blendValue = 90.0 + }, + ] + m_blendValueSource = "Parameter" + m_param = + { + m_id = 1076241868 + } + m_blendKeyType = "BlendKey_UserValue" + m_bLockBlendOnReset = false + m_bSyncCycles = true + m_bLoop = true + m_bLockWhenWaning = true + m_damping = + { + _class = "CAnimInputDamping" + m_speedFunction = "NoDamping" + m_fSpeedScale = 1.0 + m_fMinSpeed = 10.0 + m_fMaxTension = 1000.0 + m_fTension = 100.0 + m_fDamping = 5.0 + } + } + }, + { + key = + { + m_id = 1100900612 + } + value = + { + _class = "CSingleFrameAnimNode" + m_sName = "Unnamed" + m_vecPosition = [ -560.0, 48.0 ] + m_nNodeID = + { + m_id = 1100900612 + } + m_sNote = "" + m_sequenceName = "putter_long" + m_nFrameIndex = 0 + m_tagSpans = [ ] + } + }, + { + key = + { + m_id = 1233287384 + } + value = + { + _class = "CSingleFrameAnimNode" + m_sName = "Unnamed" + m_vecPosition = [ -560.0, -48.0 ] + m_nNodeID = + { + m_id = 1233287384 + } + m_sNote = "" + m_sequenceName = "putter_short" + m_nFrameIndex = 0 + m_tagSpans = [ ] + } + }, + { + key = + { + m_id = 2066078636 + } + value = + { + _class = "CSingleFrameAnimNode" + m_sName = "Unnamed" + m_vecPosition = [ -560.0, 0.0 ] + m_nNodeID = + { + m_id = 2066078636 + } + m_sNote = "" + m_sequenceName = "putter_default" + m_nFrameIndex = 0 + m_tagSpans = [ ] + } + }, + ] + } + m_pParameterList = + { + _class = "CAnimParameterList" + m_Parameters = + [ + { + _class = "CFloatAnimParameter" + m_name = "putter_length" + m_id = + { + m_id = 1076241868 + } + m_previewButton = "ANIMPARAM_BUTTON_NONE" + m_bUseMostRecentValue = false + m_bAutoReset = false + m_fDefaultValue = 72.5 + m_fMinValue = 60.0 + m_fMaxValue = 90.0 + }, + ] + } + m_pTagManager = + { + _class = "CAnimTagManager" + m_tags = [ ] + } + m_pMovementManager = + { + _class = "CAnimMovementManager" + m_MotorList = + { + _class = "CAnimMotorList" + m_motors = [ ] + } + m_MovementSettings = + { + _class = "CAnimMovementSettings" + m_bShouldCalculateSlope = false + } + } + m_pSettingsManager = + { + _class = "CAnimGraphSettingsManager" + m_settingsGroups = + [ + { + _class = "CAnimGraphGeneralSettings" + m_iGridSnap = 16 + }, + { + _class = "CAnimGraphNetworkSettings" + }, + ] + } + m_pActivityValuesList = + { + _class = "CActivityValueList" + m_activities = [ ] + } + m_previewModels = + [ + "models/gameplay/putter/putter.vmdl", + ] + m_boneMergeModels = [ ] + m_cameraSettings = + { + m_flFov = 60.0 + m_sLockBoneName = "root" + m_bLockCamera = false + m_bViewModelCamera = false + } +} \ No newline at end of file diff --git a/Assets/models/gameplay/putter/putter.fbx b/Assets/models/gameplay/putter/putter.fbx new file mode 100644 index 0000000..064c37d --- /dev/null +++ b/Assets/models/gameplay/putter/putter.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8e2fa3504f7ece9eb18edc57fec7ed9b7b295376f5e709adb997e1d516fa7a1 +size 101136 diff --git a/Assets/models/gameplay/putter/putter.vmdl b/Assets/models/gameplay/putter/putter.vmdl new file mode 100644 index 0000000..f52ff68 --- /dev/null +++ b/Assets/models/gameplay/putter/putter.vmdl @@ -0,0 +1,134 @@ + +{ + rootNode = + { + _class = "RootNode" + children = + [ + { + _class = "MaterialGroupList" + children = + [ + { + _class = "DefaultMaterialGroup" + remaps = + [ + { + from = "putter.vmat" + to = "models/gameplay/putter/materials/putter.vmat" + }, + ] + use_global_default = false + global_default_material = "materials/default.vmat" + }, + ] + }, + { + _class = "RenderMeshList" + children = + [ + { + _class = "RenderMeshFile" + filename = "models/gameplay/putter/putter.fbx" + import_translation = [ 0.0, 0.0, 0.0 ] + import_rotation = [ 0.0, 0.0, 0.0 ] + import_scale = 1.0 + align_origin_x_type = "None" + align_origin_y_type = "None" + align_origin_z_type = "None" + parent_bone = "" + import_filter = + { + exclude_by_default = true + exception_list = + [ + "polySurface2", + "pCube1", + ] + } + }, + ] + }, + { + _class = "AnimationList" + children = + [ + { + _class = "AnimFile" + name = "putter_default" + activity_name = "" + activity_weight = 1 + weight_list_name = "" + fade_in_time = 0.2 + fade_out_time = 0.2 + looping = false + delta = false + worldSpace = false + hidden = false + anim_markup_ordered = false + disable_compression = false + disable_interpolation = false + enable_scale = false + source_filename = "models/gameplay/putter/putter.fbx" + start_frame = -1 + end_frame = -1 + framerate = -1.0 + take = 0 + reverse = false + }, + { + _class = "AnimFile" + name = "putter_short" + activity_name = "" + activity_weight = 1 + weight_list_name = "" + fade_in_time = 0.2 + fade_out_time = 0.2 + looping = false + delta = false + worldSpace = false + hidden = false + anim_markup_ordered = false + disable_compression = false + disable_interpolation = false + enable_scale = false + source_filename = "models/gameplay/putter/putter.fbx" + start_frame = 9 + end_frame = -1 + framerate = -1.0 + take = 0 + reverse = false + }, + { + _class = "AnimFile" + name = "putter_long" + activity_name = "" + activity_weight = 1 + weight_list_name = "" + fade_in_time = 0.2 + fade_out_time = 0.2 + looping = false + delta = false + worldSpace = false + hidden = false + anim_markup_ordered = false + disable_compression = false + disable_interpolation = false + enable_scale = false + source_filename = "models/gameplay/putter/putter.fbx" + start_frame = 19 + end_frame = -1 + framerate = -1.0 + take = 0 + reverse = false + }, + ] + default_root_bone_name = "" + }, + ] + model_archetype = "" + primary_associated_entity = "" + anim_graph_name = "models/gameplay/putter/minigolf_putter.vanmgrph" + base_model_name = "" + } +} \ No newline at end of file diff --git a/Assets/models/headset/headset.fbx b/Assets/models/headset/headset.fbx new file mode 100644 index 0000000..1696c5a --- /dev/null +++ b/Assets/models/headset/headset.fbx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b4f7f08e8b1c5a63bdf8cfb7ed81d9bc9f899f901661b315874706bd52d07e5f +size 231264 diff --git a/Assets/models/headset/headset.vmdl b/Assets/models/headset/headset.vmdl new file mode 100644 index 0000000..a275283 --- /dev/null +++ b/Assets/models/headset/headset.vmdl @@ -0,0 +1,51 @@ + +{ + rootNode = + { + _class = "RootNode" + children = + [ + { + _class = "MaterialGroupList" + children = + [ + { + _class = "DefaultMaterialGroup" + remaps = [ ] + use_global_default = true + global_default_material = "models/headset/materials/headset.vmat" + }, + ] + }, + { + _class = "RenderMeshList" + children = + [ + { + _class = "RenderMeshFile" + filename = "models/headset/headset.fbx" + import_translation = [ 0.0, 0.0, 0.0 ] + import_rotation = [ 0.0, 0.0, 0.0 ] + import_scale = 1.0 + align_origin_x_type = "None" + align_origin_y_type = "None" + align_origin_z_type = "None" + parent_bone = "" + import_filter = + { + exclude_by_default = true + exception_list = + [ + "generic_hmd2", + ] + } + }, + ] + }, + ] + model_archetype = "" + primary_associated_entity = "" + anim_graph_name = "" + base_model_name = "" + } +} \ No newline at end of file diff --git a/Assets/models/headset/materials/headset.vmat b/Assets/models/headset/materials/headset.vmat new file mode 100644 index 0000000..e385f7e --- /dev/null +++ b/Assets/models/headset/materials/headset.vmat @@ -0,0 +1,42 @@ +// THIS FILE IS AUTO-GENERATED + +Layer0 +{ + shader "shaders/complex.shader" + + //---- PBR ---- + F_SPECULAR 1 + + //---- Ambient Occlusion ---- + g_flAmbientOcclusionDirectDiffuse "0.000" + g_flAmbientOcclusionDirectSpecular "0.000" + TextureAmbientOcclusion "models/headset/materials/headset_ao.png" + + //---- Color ---- + g_flModelTintAmount "1.000" + g_vColorTint "[1.000000 1.000000 1.000000 0.000000]" + TextureColor "models/headset/materials/headset_color.png" + + //---- Fade ---- + g_flFadeExponent "1.000" + + //---- Fog ---- + g_bFogEnabled "1" + + //---- Metalness ---- + g_flMetalness "0.000" + + //---- Normal ---- + TextureNormal "models/headset/materials/headset_normal.png" + + //---- Roughness ---- + g_flRoughnessScaleFactor "1.000" + TextureRoughness "models/headset/materials/headset_rough.png" + + //---- Texture Coordinates ---- + g_nScaleTexCoordUByModelScaleAxis "0" + g_nScaleTexCoordVByModelScaleAxis "0" + g_vTexCoordOffset "[0.000 0.000]" + g_vTexCoordScale "[1.000 1.000]" + g_vTexCoordScrollSpeed "[0.000 0.000]" +} \ No newline at end of file diff --git a/Assets/models/headset/materials/headset_AO.png b/Assets/models/headset/materials/headset_AO.png new file mode 100644 index 0000000..02b0620 --- /dev/null +++ b/Assets/models/headset/materials/headset_AO.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d38159d451fbd04c15cb87948afb198c92ca7301c01ef844198e1ed10d545579 +size 4468482 diff --git a/Assets/models/headset/materials/headset_Color.png b/Assets/models/headset/materials/headset_Color.png new file mode 100644 index 0000000..aa35f56 --- /dev/null +++ b/Assets/models/headset/materials/headset_Color.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96e93027c29f0bf797f7d3d69db3a7f0eeffa03ad65a1d8b15c84c764db9e1c1 +size 1081340 diff --git a/Assets/models/headset/materials/headset_Metal.png b/Assets/models/headset/materials/headset_Metal.png new file mode 100644 index 0000000..48032bd --- /dev/null +++ b/Assets/models/headset/materials/headset_Metal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41a8c2d58782abca9d4b79dc2b4d59fa460a731b081212ba4723c7b64017b780 +size 4166 diff --git a/Assets/models/headset/materials/headset_Normal.png b/Assets/models/headset/materials/headset_Normal.png new file mode 100644 index 0000000..b197767 --- /dev/null +++ b/Assets/models/headset/materials/headset_Normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11fd2f2bcf1bf113f30bdfcfcba81961782a5156e3840a9dc4b31f561261cf35 +size 6968289 diff --git a/Assets/models/headset/materials/headset_Rough.png b/Assets/models/headset/materials/headset_Rough.png new file mode 100644 index 0000000..9a1ce65 --- /dev/null +++ b/Assets/models/headset/materials/headset_Rough.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc0c4c2c804837c6b82359d0c7581a33f48a34e8eb8539cdb8b13f0a62b73f25 +size 1381783 diff --git a/Assets/prefabs/vrplayer.prefab b/Assets/prefabs/vrplayer.prefab new file mode 100644 index 0000000..9557673 --- /dev/null +++ b/Assets/prefabs/vrplayer.prefab @@ -0,0 +1,188 @@ +{ + "RootObject": { + "__guid": "aa8e1ec0-613c-443a-aaca-ccc1379012db", + "Flags": 0, + "Name": "vrplayer", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.VR.VRAnchor", + "__guid": "52938873-74a1-4ca2-88b4-3e1c90637131" + }, + { + "__type": "VRGolfPlayer", + "__guid": "589e46fe-0a69-4c67-851a-5b2c7c75bec4", + "GolfPutter": { + "_type": "gameobject", + "go": "822d0e1e-0166-4c22-be0f-41db05f91222" + }, + "Head": { + "_type": "gameobject", + "go": "9d527937-bcdb-4aa5-beba-c96f94e00d2e" + }, + "PutterHead": { + "_type": "gameobject", + "go": "f147b5c9-5094-47c0-aaea-ead2466fb6c3" + } + } + ], + "Children": [ + { + "__guid": "9d527937-bcdb-4aa5-beba-c96f94e00d2e", + "Flags": 0, + "Name": "Head", + "Tags": "maincamera", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.CameraComponent", + "__guid": "d63760d9-6727-4839-856a-f2997b1d8073", + "BackgroundColor": "0.33333,0.46275,0.52157,1", + "ClearFlags": "All", + "FieldOfView": 60, + "IsMainCamera": true, + "Orthographic": false, + "OrthographicHeight": 1204, + "Priority": 1, + "RenderExcludeTags": "", + "RenderTags": "", + "TargetEye": "Both", + "Viewport": "0,0,1,1", + "ZFar": 10000, + "ZNear": 1 + }, + { + "__type": "Sandbox.VR.VRTrackedObject", + "__guid": "4a404d51-75b8-4cec-a6a7-fc708ce3498a", + "PoseSource": "Head", + "TrackingType": "All", + "UseRelativeTransform": false + }, + { + "__type": "Sandbox.Voice", + "__guid": "217417a1-8ca3-4735-9302-4bdc2e45dc5c", + "Loopback": false, + "Mode": "AlwaysOn", + "MorphScale": 3, + "MorphSmoothTime": 0.1, + "PushToTalkInput": "voice", + "Volume": 1, + "WorldspacePlayback": false + } + ], + "Children": [ + { + "__guid": "20f3d652-b2da-41dc-a87b-b9fe7f7f7d3a", + "Flags": 0, + "Name": "headset", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.ModelRenderer", + "__guid": "248a52de-3efc-4037-b5c4-77c090edd8e1", + "BodyGroups": 18446744073709551615, + "Model": "models/headset/headset.vmdl", + "RenderOptions": { + "GameLayer": true, + "OverlayLayer": false, + "BloomLayer": false, + "AfterUILayer": false + }, + "RenderType": "ShadowsOnly", + "Tint": "1,1,1,1" + } + ] + } + ] + }, + { + "__guid": "42f56ebd-88e1-4372-9bdc-ba66ccd72ccd", + "Flags": 0, + "Name": "LeftHand", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.VR.VRTrackedObject", + "__guid": "2fa6f0a2-7d83-45cf-8655-836fa6c3481e", + "PoseSource": "LeftHand", + "TrackingType": "All", + "UseRelativeTransform": false + } + ] + }, + { + "__guid": "91bc6cac-32b8-4956-aeec-f1a6a80f4e18", + "Flags": 0, + "Name": "RightHand", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.VR.VRTrackedObject", + "__guid": "21eef2ed-24d1-4335-a57c-18868a989dde", + "PoseSource": "RightHand", + "TrackingType": "All", + "UseRelativeTransform": false + } + ] + }, + { + "__guid": "822d0e1e-0166-4c22-be0f-41db05f91222", + "Flags": 0, + "Name": "putter", + "Enabled": true, + "Components": [ + { + "__type": "Sandbox.SkinnedModelRenderer", + "__guid": "1accfb29-dba0-495b-ba33-4b534b1099d1", + "BodyGroups": 18446744073709551615, + "CreateBoneObjects": true, + "Model": "models/gameplay/putter/putter.vmdl", + "Morphs": {}, + "Parameters": { + "bools": {}, + "ints": {}, + "floats": {}, + "vectors": {}, + "rotations": {} + }, + "RenderOptions": { + "GameLayer": true, + "OverlayLayer": false, + "BloomLayer": false, + "AfterUILayer": false + }, + "RenderType": "On", + "Tint": "1,1,1,1", + "UseAnimGraph": true + } + ], + "Children": [ + { + "__guid": "c6b8e687-6eaa-4411-94e3-fe14e4d6ec36", + "Flags": 4, + "Name": "root", + "Rotation": "0.4999999,0.4999999,0.4999999,0.5000002", + "Enabled": true, + "Children": [ + { + "__guid": "f147b5c9-5094-47c0-aaea-ead2466fb6c3", + "Flags": 4, + "Name": "putter_head", + "Position": "0.000006805252,0.000006805252,28.54329", + "Enabled": true + } + ] + } + ] + } + ], + "__variables": [] + }, + "ShowInMenu": false, + "MenuPath": null, + "MenuIcon": null, + "DontBreakAsTemplate": false, + "ResourceVersion": 1, + "__references": [], + "__version": 1 +} \ No newline at end of file diff --git a/Code/Ball/VRGolfPlayer.cs b/Code/Ball/VRGolfPlayer.cs new file mode 100644 index 0000000..7a41ea1 --- /dev/null +++ b/Code/Ball/VRGolfPlayer.cs @@ -0,0 +1,206 @@ +using Sandbox; +using Sandbox.VR; +using System.Diagnostics; + +public sealed class VRGolfPlayer : Component +{ + public float ShotPower { get; set; } = 0f; + + [Property] GameObject Head { get; set; } + + [Property] GameObject GolfPutter { get; set; } + + [Property] GameObject PutterHead { get; set; } + + private Vector3 lastFramePosition; + private List velocityBuffer = new List(); + private const int velocityBufferSize = 5; + + public bool RightDominant { get; set; } = true; + + RealTimeSince timeSinceOutOfPlay; + + SkinnedModelRenderer golfPutterRenderer; + + [Sync] Vector3 HeadPosition { get; set; } + [Sync] Rotation HeadRotation { get; set; } + + [Sync] Vector3 PutterPosition { get; set; } + [Sync] Rotation PutterRotation { get; set; } + + VRController PrimaryHand => RightDominant ? Input.VR.RightHand : Input.VR.LeftHand; + + List UIPanels { get; set; } = new List(); + + protected override async void OnStart() + { + golfPutterRenderer = GolfPutter.GetComponent(); + if ( IsProxy ) + { + Head.GetComponentInChildren().RenderType = ModelRenderer.ShadowRenderType.On; + } + else + { + foreach ( var item in Scene.GetAll() ) + { + UIPanels.Add( item.GameObject ); + var worldpanel = item.AddComponent(); + worldpanel.PanelSize = new Vector2( 102.4f, 51.2f ); + worldpanel.RenderScale = 0.075f; + worldpanel.RenderOptions.Overlay = true; + item.Destroy(); + } + + await Task.DelaySeconds( 1f ); + + foreach ( var item in UIPanels ) + { + item.Enabled = false; + await Task.Frame(); + await Task.Frame(); + await Task.Frame(); + item.Enabled = true; + } + } + } + + protected override void OnPreRender() + { + if ( IsProxy ) + { + Head.LocalPosition = Vector3.Lerp( Head.LocalPosition, HeadPosition, 0.9f ); + Head.LocalRotation = Rotation.Lerp( Head.LocalRotation, HeadRotation, 0.9f ); + + GolfPutter.LocalPosition = Vector3.Lerp( GolfPutter.LocalPosition, PutterPosition, 0.9f ); + GolfPutter.LocalRotation = Rotation.Lerp( GolfPutter.LocalRotation, PutterRotation, 0.9f ); + } + else + { + HeadPosition = Head.LocalPosition; + HeadRotation = Head.LocalRotation; + + PutterPosition = GolfPutter.LocalPosition; + PutterRotation = GolfPutter.LocalRotation; + + foreach ( var item in UIPanels ) + { + item.WorldPosition = PrimaryHand.Transform.Position; + item.WorldRotation = PrimaryHand.Transform.Rotation * Rotation.FromYaw( -90f * (RightDominant ? -1f : 1f) ) * Rotation.FromRoll( -90f * (RightDominant ? -1f : 1f) ); + } + + + GolfPutter.Transform.World = PrimaryHand.Transform; + GolfPutter.WorldRotation *= Rotation.FromPitch( 35f ); + + } + } + + protected override void OnFixedUpdate() + { + if ( !Ball.Local.IsValid() || IsProxy ) + { + return; + } + + if ( Input.VR.LeftHand.ButtonA.IsPressed ) + { + RightDominant = false; + } + + if ( Input.VR.RightHand.ButtonA.IsPressed ) + { + RightDominant = true; + } + + GolfPutter.Transform.World = PrimaryHand.Transform; + GolfPutter.WorldRotation *= Rotation.FromPitch( 35f ); + + var currentFrameVelocity = PutterHead.WorldPosition - lastFramePosition; + + velocityBuffer.Add( currentFrameVelocity ); + + if ( velocityBuffer.Count > velocityBufferSize ) + { + velocityBuffer.RemoveAt( 0 ); + } + + var tr = Scene.Trace.Ray( GolfPutter.WorldPosition - GolfPutter.WorldRotation.Forward * 7.5f, GolfPutter.WorldPosition + GolfPutter.WorldRotation.Forward * 90f ).Run(); + + if ( tr.Hit ) + { + golfPutterRenderer.Set( "putter_length", tr.Distance * 2f ); + } + + var averagedVelocity = Vector3.Zero; + foreach ( var velocity in velocityBuffer ) + { + averagedVelocity += velocity; + } + + averagedVelocity /= velocityBuffer.Count; + + Ball.Local.Controller.Camera.Enabled = false; + + var goToBall = !Ball.Local.Controller.InPlay || Input.VR.LeftHand.Trigger.Value > 0.5f || Input.VR.RightHand.Trigger.Value > 0.5f; + + if ( goToBall ) + { + WorldPosition = Ball.Local.WorldPosition; + } + + if ( Ball.Local.Controller.InPlay ) + { + timeSinceOutOfPlay = 0f; + ShotPower = 0f; + } + + if ( timeSinceOutOfPlay < 0.5f ) + { + golfPutterRenderer.Tint = Color.White.WithAlpha( 0.5f ); + } + else + { + golfPutterRenderer.Tint = Color.White.WithAlpha( 1f ); + } + + var putterHeadForward = Vector3.Dot( averagedVelocity, PutterHead.WorldRotation.Forward ) > 0 ? PutterHead.WorldRotation.Forward.WithZ( 0 ) : PutterHead.WorldRotation.Backward.WithZ( 0 ); + + var direction = (averagedVelocity.WithZ( 0 ) + putterHeadForward).Normal; + var ballRadius = Ball.Local.Rigidbody.PhysicsBody.GetBounds().Size.z / 2; + + var steps = 10; + var stepSize = 1f / steps; + + bool hitBallInbetween = false; + + for ( int i = 0; i < steps; i++ ) + { + var interpolatedPosition = Vector3.Lerp( lastFramePosition, PutterHead.WorldPosition, i * stepSize ); + + if ( Vector3.DistanceBetween( interpolatedPosition, Ball.Local.WorldPosition ) < ballRadius * 2f ) + { + hitBallInbetween = true; + break; + } + } + + if ( timeSinceOutOfPlay > 0.5f && (Vector3.DistanceBetween( PutterHead.WorldPosition, Ball.Local.WorldPosition ) < ballRadius * 2f || hitBallInbetween) ) + { + ShotPower = Math.Clamp( averagedVelocity.Length / 7.5f, 0f, 1f ); + PrimaryHand.TriggerHaptics( HapticEffect.SoftImpact ); + } + + if ( ShotPower > 0.0f && !Ball.Local.Controller.InPlay ) + { + Ball.Local.Stroke( Rotation.LookAt( direction ).Yaw(), ShotPower ); + + Ball.Local.Controller.InPlay = true; + Ball.Local.Controller.LastShotPower = ShotPower; + ShotPower = 0f; + + IGameEvent.Post( x => x.BallStroke( Ball.Local ) ); + } + + lastFramePosition = PutterHead.WorldPosition; + } +} diff --git a/Code/GameLoop/GameManager.cs b/Code/GameLoop/GameManager.cs index f08712a..657a2e5 100644 --- a/Code/GameLoop/GameManager.cs +++ b/Code/GameLoop/GameManager.cs @@ -65,6 +65,12 @@ public void SpawnPlayerForConnection( Connection channel ) var player = playerGo.Components.Get( true ); playerGo.NetworkSpawn( channel ); + if ( Game.IsRunningInVR ) + { + var vrPlayerGo = GameObject.Clone( "prefabs/vrplayer.prefab", new CloneConfig { Name = $"VR Player - {channel.DisplayName}", StartEnabled = true, Transform = startLocation } ); + vrPlayerGo.NetworkSpawn( channel ); + } + IPlayerEvent.Post( x => x.OnSpawned( player ) ); } From d6ec72bb51586f0a8217b131d18a9809a271de2b Mon Sep 17 00:00:00 2001 From: Brian Lindenhof Date: Fri, 18 Oct 2024 17:09:14 +0200 Subject: [PATCH 2/5] Initial menu interaction mode --- Code/Ball/VRGolfPlayer.cs | 71 +++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/Code/Ball/VRGolfPlayer.cs b/Code/Ball/VRGolfPlayer.cs index 7a41ea1..91c399d 100644 --- a/Code/Ball/VRGolfPlayer.cs +++ b/Code/Ball/VRGolfPlayer.cs @@ -32,9 +32,18 @@ public sealed class VRGolfPlayer : Component List UIPanels { get; set; } = new List(); + public bool MenuMode { get; set; } + protected override async void OnStart() { + if ( !Game.IsRunningInVR ) + { + DestroyGameObject(); + return; + } + golfPutterRenderer = GolfPutter.GetComponent(); + if ( IsProxy ) { Head.GetComponentInChildren().RenderType = ModelRenderer.ShadowRenderType.On; @@ -57,8 +66,6 @@ protected override async void OnStart() { item.Enabled = false; await Task.Frame(); - await Task.Frame(); - await Task.Frame(); item.Enabled = true; } } @@ -82,12 +89,25 @@ protected override void OnPreRender() PutterPosition = GolfPutter.LocalPosition; PutterRotation = GolfPutter.LocalRotation; - foreach ( var item in UIPanels ) + if ( !MenuMode ) { - item.WorldPosition = PrimaryHand.Transform.Position; - item.WorldRotation = PrimaryHand.Transform.Rotation * Rotation.FromYaw( -90f * (RightDominant ? -1f : 1f) ) * Rotation.FromRoll( -90f * (RightDominant ? -1f : 1f) ); + foreach ( var item in UIPanels ) + { + item.WorldPosition = PrimaryHand.Transform.Position; + item.WorldRotation = PrimaryHand.Transform.Rotation * Rotation.FromYaw( -90f * (RightDominant ? -1f : 1f) ) * Rotation.FromRoll( -90f * (RightDominant ? -1f : 1f) ); + } + } + else + { + foreach ( var item in UIPanels ) + { + item.WorldPosition = WorldPosition + WorldRotation.Forward * 39f + Vector3.Up * 39f; + var worldpanel = item.GetComponent(); + worldpanel.PanelSize = new Vector2( 1024f, 512f ); + worldpanel.RenderScale = 0.5f; + item.WorldRotation = WorldRotation * Rotation.FromPitch( -35f ); + } } - GolfPutter.Transform.World = PrimaryHand.Transform; GolfPutter.WorldRotation *= Rotation.FromPitch( 35f ); @@ -95,9 +115,40 @@ protected override void OnPreRender() } } + Sandbox.UI.WorldInput worldInput; + + public void DoWorldInput() + { + if ( worldInput == null ) + { + worldInput = new Sandbox.UI.WorldInput(); + worldInput.Enabled = true; + } + + var inputRay = new Ray( PrimaryHand.Transform.Position, PrimaryHand.Transform.Rotation.Forward ); + + worldInput.Ray = inputRay; + + if ( worldInput.Hovered.FindRootPanel() is Sandbox.UI.WorldPanel WP && WP.RayToLocalPosition( inputRay, out Vector2 pos, out float paneldistance ) ) + { + Gizmo.Draw.Line( inputRay.Position, inputRay.Position + inputRay.Forward * paneldistance ); + } + else + { + Gizmo.Draw.Line( inputRay.Position, inputRay.Position + inputRay.Forward * 100f ); + } + + worldInput.MouseLeftPressed = PrimaryHand.Trigger.Value > 0.5f; + } + protected override void OnFixedUpdate() { - if ( !Ball.Local.IsValid() || IsProxy ) + if ( !Ball.Local.IsValid() ) + { + MenuMode = true; + } + + if ( IsProxy ) { return; } @@ -115,6 +166,12 @@ protected override void OnFixedUpdate() GolfPutter.Transform.World = PrimaryHand.Transform; GolfPutter.WorldRotation *= Rotation.FromPitch( 35f ); + if ( MenuMode ) + { + DoWorldInput(); + return; + } + var currentFrameVelocity = PutterHead.WorldPosition - lastFramePosition; velocityBuffer.Add( currentFrameVelocity ); From 02b314db0f1b8e7babdfb8c9c648d29e3517d725 Mon Sep 17 00:00:00 2001 From: Brian Lindenhof Date: Fri, 18 Oct 2024 18:28:43 +0200 Subject: [PATCH 3/5] Spawn VR player in the main menu but don't replace the screen panel with a world panel because it's all fucked rendering-wise --- Assets/scenes/menu.scene | 18 +++++++++--------- Code/Ball/VRGolfPlayer.cs | 15 +++++++++++---- Code/UI/MainMenu/MainMenuComponent.razor | 11 +++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Assets/scenes/menu.scene b/Assets/scenes/menu.scene index b750bfc..c79c18a 100644 --- a/Assets/scenes/menu.scene +++ b/Assets/scenes/menu.scene @@ -754,7 +754,7 @@ "__guid": "d030e52c-a442-4446-8837-d5e7f0250a84", "Flags": 0, "Name": "corner", - "Position": "-297.1039,-863.9974,-361.0106", + "Position": "-297.1039,-863.9968,-361.0106", "Rotation": "-0.00000002980232,0.00000002980232,0.7071067,0.7071067", "Tags": "gridtile", "Enabled": true, @@ -978,7 +978,7 @@ "__guid": "3ff8588b-b9c7-49db-ad09-b44301988033", "Flags": 0, "Name": "hill-corner", - "Position": "-169.104,-863.9974,-361.0106", + "Position": "-169.104,-863.9968,-361.0106", "Tags": "gridtile", "Enabled": true, "Components": [ @@ -1009,7 +1009,7 @@ "__guid": "d5b41e85-bc7c-4cfe-8e73-6cd2b9b6cdfb", "Flags": 0, "Name": "hole-square", - "Position": "-41.10403,-863.9974,-361.0106", + "Position": "-41.10403,-863.9968,-361.0106", "Rotation": "0,0.00000004371139,0.9999999,0", "Tags": "gridtile", "Enabled": true, @@ -1041,7 +1041,7 @@ "__guid": "3aee6ff8-705c-4a5b-85a5-d49153e35d7c", "Flags": 0, "Name": "round-corner-a", - "Position": "86.89596,-863.9974,-361.0106", + "Position": "86.89596,-863.9968,-361.0106", "Tags": "gridtile", "Enabled": true, "Components": [ @@ -1072,7 +1072,7 @@ "__guid": "cdce4061-daeb-4858-8ab2-0fcd76be4764", "Flags": 0, "Name": "round-corner-b", - "Position": "214.8959,-991.9974,-361.0106", + "Position": "214.8959,-991.9968,-361.0106", "Tags": "gridtile", "Enabled": true, "Components": [ @@ -1103,7 +1103,7 @@ "__guid": "d2b90636-48a3-4219-ac05-ae97a0940fab", "Flags": 0, "Name": "round-corner-b", - "Position": "86.89594,-991.9974,-361.0106", + "Position": "86.89594,-991.9968,-361.0106", "Rotation": "0,0.00000004371139,0.9999999,0", "Tags": "gridtile", "Enabled": true, @@ -1462,7 +1462,7 @@ "__guid": "8eb46311-5e97-467e-9a19-bf9e6124a549", "Flags": 0, "Name": "round-corner-b", - "Position": "-191.8081,-900.0823,-425.012", + "Position": "-191.8081,-900.0817,-425.012", "Rotation": "0,0,0.7071067,0.7071068", "Tags": "gridtile", "Enabled": true, @@ -1494,7 +1494,7 @@ "__guid": "15a9c600-2333-42bd-a032-8c34ab4aec78", "Flags": 0, "Name": "round-corner-b", - "Position": "-63.80814,-900.0826,-425.012", + "Position": "-63.80814,-900.082,-425.012", "Tags": "gridtile", "Enabled": true, "Components": [ @@ -1620,7 +1620,7 @@ "__guid": "c1900339-de38-4475-a7ca-7b76b2bc116d", "Flags": 0, "Name": "hole-square", - "Position": "-319.8081,-900.0823,-425.012", + "Position": "-319.8081,-900.0817,-425.012", "Rotation": "0,0,0.7071067,0.7071068", "Tags": "gridtile", "Enabled": true, diff --git a/Code/Ball/VRGolfPlayer.cs b/Code/Ball/VRGolfPlayer.cs index 91c399d..2e67bf4 100644 --- a/Code/Ball/VRGolfPlayer.cs +++ b/Code/Ball/VRGolfPlayer.cs @@ -42,13 +42,18 @@ protected override async void OnStart() return; } + if ( !Ball.Local.IsValid() ) + { + MenuMode = true; + } + golfPutterRenderer = GolfPutter.GetComponent(); if ( IsProxy ) { Head.GetComponentInChildren().RenderType = ModelRenderer.ShadowRenderType.On; } - else + else if ( !MenuMode ) { foreach ( var item in Scene.GetAll() ) { @@ -66,6 +71,7 @@ protected override async void OnStart() { item.Enabled = false; await Task.Frame(); + await Task.Frame(); item.Enabled = true; } } @@ -104,8 +110,8 @@ protected override void OnPreRender() item.WorldPosition = WorldPosition + WorldRotation.Forward * 39f + Vector3.Up * 39f; var worldpanel = item.GetComponent(); worldpanel.PanelSize = new Vector2( 1024f, 512f ); - worldpanel.RenderScale = 0.5f; - item.WorldRotation = WorldRotation * Rotation.FromPitch( -35f ); + worldpanel.RenderScale = 1f; + item.WorldRotation = WorldRotation; } } @@ -129,7 +135,7 @@ public void DoWorldInput() worldInput.Ray = inputRay; - if ( worldInput.Hovered.FindRootPanel() is Sandbox.UI.WorldPanel WP && WP.RayToLocalPosition( inputRay, out Vector2 pos, out float paneldistance ) ) + if ( worldInput.Hovered.IsValid() && worldInput.Hovered.FindRootPanel() is Sandbox.UI.WorldPanel WP && WP.RayToLocalPosition( inputRay, out Vector2 pos, out float paneldistance ) ) { Gizmo.Draw.Line( inputRay.Position, inputRay.Position + inputRay.Forward * paneldistance ); } @@ -146,6 +152,7 @@ protected override void OnFixedUpdate() if ( !Ball.Local.IsValid() ) { MenuMode = true; + return; } if ( IsProxy ) diff --git a/Code/UI/MainMenu/MainMenuComponent.razor b/Code/UI/MainMenu/MainMenuComponent.razor index 17ff29a..499fc02 100644 --- a/Code/UI/MainMenu/MainMenuComponent.razor +++ b/Code/UI/MainMenu/MainMenuComponent.razor @@ -5,3 +5,14 @@ + +@code{ + protected override void OnStart() + { + base.OnStart(); + if (Game.IsRunningInVR) + { + GameObject.Clone("prefabs/vrplayer.prefab"); + } + } +} From 1ec61c74db5cb34103051e176fc22d485e9eb598 Mon Sep 17 00:00:00 2001 From: Brian Lindenhof Date: Fri, 18 Oct 2024 18:33:24 +0200 Subject: [PATCH 4/5] Don't need to wait 2 frames, one is enough --- Code/Ball/VRGolfPlayer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Ball/VRGolfPlayer.cs b/Code/Ball/VRGolfPlayer.cs index 2e67bf4..827881c 100644 --- a/Code/Ball/VRGolfPlayer.cs +++ b/Code/Ball/VRGolfPlayer.cs @@ -65,13 +65,13 @@ protected override async void OnStart() item.Destroy(); } - await Task.DelaySeconds( 1f ); + await Task.DelaySeconds( 0.5f ); + //Screen => World panel conversion needs me to re-enable the gameobjects? Idk it seems weird but this worked... foreach ( var item in UIPanels ) { item.Enabled = false; await Task.Frame(); - await Task.Frame(); item.Enabled = true; } } From 3a09449039c589e3911a1b1d93033d222494b60a Mon Sep 17 00:00:00 2001 From: Brian Lindenhof Date: Fri, 18 Oct 2024 20:38:46 +0200 Subject: [PATCH 5/5] Add joystick snap rotation --- Code/Ball/VRGolfPlayer.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Code/Ball/VRGolfPlayer.cs b/Code/Ball/VRGolfPlayer.cs index 827881c..014b296 100644 --- a/Code/Ball/VRGolfPlayer.cs +++ b/Code/Ball/VRGolfPlayer.cs @@ -147,6 +147,9 @@ public void DoWorldInput() worldInput.MouseLeftPressed = PrimaryHand.Trigger.Value > 0.5f; } + bool canRotate; + RealTimeSince timeSinceRotated; + protected override void OnFixedUpdate() { if ( !Ball.Local.IsValid() ) @@ -170,6 +173,28 @@ protected override void OnFixedUpdate() RightDominant = true; } + if ( canRotate ) + { + if ( PrimaryHand.Joystick.Value.x > 0.5f ) + { + WorldRotation *= Rotation.FromYaw( -30f ); + canRotate = false; + timeSinceRotated = 0f; + } + + if ( PrimaryHand.Joystick.Value.x < -0.5f ) + { + WorldRotation *= Rotation.FromYaw( 30f ); + canRotate = false; + timeSinceRotated = 0f; + } + } + + if ( !canRotate && (timeSinceRotated > 0.5f || PrimaryHand.Joystick.Value.Length < 0.5f) ) + { + canRotate = true; + } + GolfPutter.Transform.World = PrimaryHand.Transform; GolfPutter.WorldRotation *= Rotation.FromPitch( 35f );