Search the Community
Showing results for tags 'use entity'.
-
Hi, I have some switches and doors (SwingingDoors) that have Use function and calls to open or light up the rooms. But now I want that when my VR controller collide with the door or the light, first detect that I can "interact" with it (atm painting a Sphere...) and when I click on controller trigger, call to "Use" function of the collided entity (door or switch). Now, I replicated the code from FPSPlayer to interact with the E Key, and is "working" but is very awful I'm trying to write what I'm doing (very very very bad) on VRPlayer function Script:UpdateWorld() local pickInfo = PickInfo() --Usable object with Trigger Button: DANI if VR:GetControllerButtonDown(VR.Right,VR.TriggerButton)==true then local p0 = controller:GetPosition(true) local p1 = Transform:Point(0,0,self.useDistance,controller,nil) if self.entity.world:Pick(p0,p1, pickInfo, self.pickradius, true) then --Looks for any entity in the hierarchy that has a "Use" function local usableentity = self:FindUsableEntity(pickInfo.entity) if usableentity~=nil then --Use the object, whatever it may be usableentity.script:Use(self) end end end self.canUse = false pickInfo = PickInfo() local p0 = controller:GetPosition() local p1 = Transform:Point(self.useDistance,self.useDistance,self.useDistance,controller,nil) if self.entity.world:Pick(p0,p1, pickInfo, self.pickradius, true) then if self:FindUsableEntity(pickInfo.entity)~=nil then self.picksphere:SetPosition(pickInfo.position); self.canUse=true else local mass = pickInfo.entity:GetMass() if mass>0 and mass<=self.maxcarryweight then self.canUse = true end end else self.picksphere:SetPosition(0,0,0) end