GalaxySugar Posted May 12, 2024 Share Posted May 12, 2024 Hello! I'm having some trouble with my Spyglass component, which forces the user's camera to focus on a target prefrab. This works perfectly fine on caveless worlds, but I can't get the FocalPoint's parent with caves enabled. I assume this is because TheFocalPoint is entirely client-side? How can I get this to work with caves? Spyglass Spoiler local Spyglass = Class(function(self, inst) self.inst = inst self.spyglass_looker = nil self.target = SpawnPrefab("cutgrass") --Placeholder. Change prefab later. end) function Spyglass:OnRemoveFromEntity() if TheFocalPoint ~= nil then TheFocalPoint.components.focalpoint:StopFocusSource(self.inst) end end --======================-- --==oO Spying Check Oo==-- --======================-- function Spyglass:IsSpying() return self.spyglass_looker ~= nil and self.spyglass_looker:IsValid() and self.spyglass_looker.sg ~= nil and self.spyglass_looker.sg:HasStateTag("spying") end --================-- --==oO UPDATE Oo==-- --================-- function Spyglass:OnUpdate() print("Are we spying : "..self:GetDebugString()) print(TheFocalPoint.entity:GetParent()) if TheFocalPoint.entity:GetParent() == self.spyglass_looker then print("Found FocalPoint Parent") if not self:IsSpying() then --Check if we have the right statetag. self:StopSpying() else --==oO Camera Oo==-- Continuously update the location of our focus point. Don't want to abandon our focus by sailing. local x, y, z = self.spyglass_looker.Transform:GetWorldPosition() local angle = (self.spyglass_looker.Transform:GetRotation() + 90) * DEGREES local dist = 45 local x1 = x + dist * math.sin(angle) local z1 = z + dist * math.cos(angle) self.target.Transform:SetPosition(x1, 0, z1) TheFocalPoint.components.focalpoint:StartFocusSource(self.inst, "Spyglass", self.target, 45, 500, 0) end end end --======================-- --==oO START SPYING Oo==-- --======================-- function Spyglass:StartSpying(doer) self.spyglass_looker = doer if self.spyglass_looker then print("I spy!") self.inst:StartUpdatingComponent(self) return true end end --=====================-- --==oO STOP SPYING Oo==-- --=====================-- function Spyglass:StopSpying() print("ATTEMPTING TO STOP SPYING") if not self:IsSpying() then self.spyglass_looker.sg:GoToState("peer_through_spyglass_pst") if TheFocalPoint ~= nil then TheFocalPoint.components.focalpoint:StopFocusSource(self.inst) end end self.spyglass_looker = nil self.inst:StopUpdatingComponent(self) end --===============-- --==oO DEBUG Oo==-- --===============-- function Spyglass:GetDebugString() return self:IsSpying() and "Is Spying" or "Not Spying" end return Spyglass Link to comment https://forums.kleientertainment.com/forums/topic/156026-thefocalpointentitygetparent-help/ Share on other sites More sharing options...
grm9 Posted May 12, 2024 Share Posted May 12, 2024 You could look at atrium_gate's/stalker's code to see how they get focus if that's what you want Link to comment https://forums.kleientertainment.com/forums/topic/156026-thefocalpointentitygetparent-help/#findComment-1713718 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now