Skip to content

Commit d9bdea7

Browse files
committed
- Added VR speaker transparency
- Make orb follow VR speakers
1 parent 7fca31e commit d9bdea7

4 files changed

Lines changed: 117 additions & 11 deletions

File tree

src/client/Gui.lua

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local CollectionService = game:GetService("CollectionService")
88
local TweenService = game:GetService("TweenService")
99
local RunService = game:GetService("RunService")
1010
local ProximityPromptService = game:GetService("ProximityPromptService")
11+
local VRService = game:GetService("VRService")
1112

1213
local Players = game:GetService("Players")
1314
local Config = require(Common.Config)
@@ -24,6 +25,8 @@ local OrbListenOnRemoteEvent = Common.Remotes.OrbListenOn
2425
local OrbListenOffRemoteEvent = Common.Remotes.OrbListenOff
2526
local OrbcamOnRemoteEvent = Common.Remotes.OrbcamOn
2627
local OrbcamOffRemoteEvent = Common.Remotes.OrbcamOff
28+
local VRSpeakerChalkEquipRemoteEvent = Common.Remotes.VRSpeakerChalkEquip
29+
local VRSpeakerChalkUnequipRemoteEvent = Common.Remotes.VRSpeakerChalkUnequip
2730

2831
local localPlayer
2932

@@ -195,9 +198,10 @@ function Gui.Init()
195198

196199
-- Do not allow Shift-C to turn _off_ orbcam that was turned on
197200
-- via the topbar button
198-
if Gui.Orbcam and not Gui.OrbcamGuiOff then
199-
return
200-
end
201+
if Gui.Orbcam and not Gui.OrbcamGuiOff then return end
202+
203+
-- Do not allow the shortcut when not attached
204+
if Gui.Orb == nil then return end
201205

202206
if Gui.OrbcamIcon:getToggleState() == "selected" then
203207
Gui.OrbcamIcon:deselect()
@@ -223,11 +227,67 @@ function Gui.Init()
223227
OrbTweeningStartRemoteEvent.OnClientEvent:Connect(Gui.OrbTweeningStart)
224228
OrbTweeningStopRemoteEvent.OnClientEvent:Connect(Gui.OrbTweeningStop)
225229

230+
-- In VR we need to tell other clients when we equip the chalk
231+
if VRService.VREnabled then
232+
local chalkTool = localPlayer.Backpack:WaitForChild("MetaChalk", 20)
233+
if chalkTool ~= nil then
234+
chalkTool.Equipped:Connect(function()
235+
VRSpeakerChalkEquipRemoteEvent:FireServer()
236+
end)
237+
chalkTool.Unequipped:Connect(function()
238+
VRSpeakerChalkUnequipRemoteEvent:FireServer()
239+
end)
240+
else
241+
print("[MetaOrb] Failed to find MetaChalk tool")
242+
end
243+
end
244+
245+
Gui.HandleVR()
226246
Gui.CreateTopbarItems()
227247

228248
print("[Orb] Gui Initialised")
229249
end
230250

251+
function Gui.MakePlayerTransparent(plr, transparency)
252+
if plr == nil then
253+
print("[MetaOrb] Passed nil player to MakePlayerTransparent")
254+
return
255+
end
256+
257+
if plr.Character == nil then return end
258+
259+
local character = plr.Character
260+
261+
for _, desc in ipairs(character:GetDescendants()) do
262+
if desc:IsA("BasePart") then
263+
desc.Transparency = 1 - (transparency * (1 - desc.Transparency))
264+
desc.CastShadow = false
265+
end
266+
end
267+
268+
-- origTransparency = 1 - 1/0.2 * (1 - newTransparency)
269+
end
270+
271+
function Gui.HandleVR()
272+
VRSpeakerChalkEquipRemoteEvent.OnClientEvent:Connect(function(speaker)
273+
if Gui.Orb == nil then return end
274+
if Gui.Orb.Speaker.Value == nil then return end
275+
if Gui.Orb.Speaker.Value ~= speaker then return end
276+
277+
if speaker == localPlayer then return end
278+
Gui.MakePlayerTransparent(speaker, 0.2)
279+
end)
280+
281+
VRSpeakerChalkUnequipRemoteEvent.OnClientEvent:Connect(function(speaker)
282+
if Gui.Orb == nil then return end
283+
if Gui.Orb.Speaker.Value == nil then return end
284+
if Gui.Orb.Speaker.Value ~= speaker then return end
285+
286+
if speaker == localPlayer then return end
287+
Gui.MakePlayerTransparent(speaker, 1/0.2)
288+
end)
289+
end
290+
231291
-- We create a part inside the player's head, whose CFrame
232292
-- is tracked by SetListener
233293
function Gui.InitEar()
@@ -430,12 +490,32 @@ function Gui.AttachSpeaker(orb)
430490

431491
-- This event fires when the running speed changes
432492
local humanoid = localPlayer.Character:WaitForChild("Humanoid")
433-
Gui.RunningConnection = humanoid.Running:Connect(function(speed)
434-
if speed == 0 then
435-
-- They were moving and then stood still
436-
OrbSpeakerMovedRemoteEvent:FireServer(Gui.Orb)
437-
end
438-
end)
493+
if VRService.VREnabled then
494+
local counter = 0
495+
local timeTillPositionCheck = 2
496+
local playerPosAtLastCheck = localPlayer.Character.PrimaryPart.Position
497+
498+
Gui.RunningConnection = RunService.Heartbeat:Connect(function(step)
499+
counter = counter + step
500+
if counter >= timeTillPositionCheck then
501+
counter -= timeTillPositionCheck
502+
503+
if localPlayer.Character ~= nil and localPlayer.Character.PrimaryPart ~= nil then
504+
if (localPlayer.Character.PrimaryPart.Position - playerPosAtLastCheck).Magnitude > 2 then
505+
OrbSpeakerMovedRemoteEvent:FireServer(Gui.Orb)
506+
end
507+
playerPosAtLastCheck = localPlayer.Character.PrimaryPart.Position
508+
end
509+
end
510+
end)
511+
else
512+
Gui.RunningConnection = humanoid.Running:Connect(function(speed)
513+
if speed == 0 then
514+
-- They were moving and then stood still
515+
OrbSpeakerMovedRemoteEvent:FireServer(Gui.Orb)
516+
end
517+
end)
518+
end
439519
end
440520

441521
function Gui.CreateTopbarItems()

src/common/Config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local Config = {
44
WaypointTag = "metaorb_waypoint",
55
PointOfInterestTag = "metaorb_poi",
66
DataStoreTag = "orb.",
7-
Version = "0.7.4",
7+
Version = "0.7.6",
88
TweenTime = 5,
99
RopeLength = 10,
1010
TransportWaitTime = 10,

src/common/Remotes.model.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
{
6161
"Name": "GetAttachments",
6262
"ClassName": "RemoteFunction"
63+
},
64+
{
65+
"Name": "VRSpeakerChalkEquip",
66+
"ClassName": "RemoteEvent"
67+
},
68+
{
69+
"Name": "VRSpeakerChalkUnequip",
70+
"ClassName": "RemoteEvent"
6371
}
6472
]
6573
}

src/server/Orb.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ local OrbcamOffRemoteEvent = Common.Remotes.OrbcamOff
2121
local GetOrbcamStatusRemoteFunction = Common.Remotes.GetOrbcamStatus
2222
local GetListeningStatusRemoteFunction = Common.Remotes.GetListeningStatus
2323
local GetAttachmentsRemoteFunction = Common.Remotes.GetAttachments
24+
local VRSpeakerChalkEquipRemoteEvent = Common.Remotes.VRSpeakerChalkEquip
25+
local VRSpeakerChalkUnequipRemoteEvent = Common.Remotes.VRSpeakerChalkUnequip
2426

2527
local speakerAttachSoundIds = { 7873470625, 7873470425,
2628
7873469842, 7873470126, 7864771146, 7864770493, 8214755036, 8214754703}
@@ -148,6 +150,14 @@ function Orb.Init()
148150
end
149151
end)
150152

153+
VRSpeakerChalkEquipRemoteEvent.OnServerEvent:Connect(function(plr)
154+
VRSpeakerChalkEquipRemoteEvent:FireAllClients(plr)
155+
end)
156+
157+
VRSpeakerChalkUnequipRemoteEvent.OnServerEvent:Connect(function(plr)
158+
VRSpeakerChalkUnequipRemoteEvent:FireAllClients(plr)
159+
end)
160+
151161
print("[Orb] Server ".. Config.Version .." initialized")
152162
end
153163

@@ -554,7 +564,15 @@ function Orb.PlayAttachSpeakerSound(orb, changeSound)
554564
end
555565

556566
function Orb.RotateGhostToFaceSpeaker(orb, ghost)
557-
if not ghost then return end
567+
if ghost == nil then
568+
print("[MetaOrb] Passed nil ghost")
569+
return
570+
end
571+
572+
if ghost.PrimaryPart == nil then
573+
print("[MetaOrb] Ghost has nil primary part")
574+
return
575+
end
558576

559577
local speakerPos = Orb.GetSpeakerPosition(orb)
560578
if not speakerPos then return end

0 commit comments

Comments
 (0)