randomdude Posted August 6, 2017 Share Posted August 6, 2017 Hello, I want the camera to switch its position once the Player hits the trigger box. Like Resident Evil or PnC-adventures. So after 20+ hours polishing my coding skill (which are still below room temperature) I came to this point here. local CamRot = {} CamRot[1] = 0 CamRot[2] = 270 CamRot[3] = 0 CamRot[4] = 0 CamRot[5] = 180 CamRot[6] = 0 local CamPos = {} CamPos[1] = 5 CamPos[2] = 10 CamPos[3] = -5 CamPos[4] = -5 CamPos[5] = 10 CamPos[6] = 5 Cam1=1 Cam2=2 function Script:Cam1()--in self.Cam1=1 end function Script:UpdateWorld() if self.Cam1==1 then self.entity:SetRotation(CamRot[1],CamRot[2],CamRot[3]) self.entity:SetPosition(CamPos[1],CamPos[2],CamPos[3]) self.component:CallOutputs("inPosition1") end end function Script:Cam2()--in self.Cam2=2 end function Script:UpdateWorld() if self.Cam2==2 then self.entity:SetRotation(CamRot[4],CamRot[5],CamRot[6]) self.entity:SetPosition(CamPos[4],CamPos[5],CamPos[6]) self.component:CallOutputs("inPosition2") end end The problem is Cam1 and Cam2 is functional but if I add a connection with the FlowGraph it triggers only the last one. Someone with a solution? Maybe I can only use one UpdateWorld function? I would like to use the GetChild, GetPosition functions and cycle the Camera between the added pivots but I dont how so far. Self-trySetup; Triggerscript: Standard, Playerscript:Thirdperson(lockedcam), Camerascript: posted one local CamRot = {} CamRot[1] = 0 CamRot[2] = 270 CamRot[3] = 0 CamRot[4] = 0 CamRot[5] = 180 CamRot[6] = 0 local CamPos = {} CamPos[1] = 5 CamPos[2] = 10 CamPos[3] = -5 CamPos[4] = -5 CamPos[5] = 10 CamPos[6] = 5 Cam1=1 function Script:Cam1()--in self.Cam1=1 self.enabled=true end function Script:UpdateWorld() if self.Cam1==1 then self.entity:SetRotation(CamRot[1],CamRot[2],CamRot[3]) self.entity:SetPosition(CamPos[1],CamPos[2],CamPos[3]) self.component:CallOutputs("inPosition1") if self.entity:SetRotation(CamRot[1],CamRot[2],CamRot[3])==true and self.entity:SetPosition(CamPos[1],CamPos[2],CamPos[3])==true then self.entity:SetRotation(CamRot[4],CamRot[5],CamRot[6]) self.entity:SetPosition(CamPos[4],CamPos[5],CamPos[6]) self.component:CallOutputs("inPosition2") end end end Here is another approch to the problem. It triggers only once as well. A Screenshot of the scene for better understanding. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 7, 2017 Share Posted August 7, 2017 13 hours ago, randomdude said: Maybe I can only use one UpdateWorld function? I would like to use the GetChild, GetPosition functions and cycle the Camera between the added pivots but I dont how so far. There can be only 1 UpdateWorld function per script. Some feedback on how to use Vec3 instead of 3 separate variables for the coordinates. local CamRot = {} CamRot[1] = Vec3(0, 270 ,0) CamRot[2] = Vec3(0, 180 ,0) self.entity:SetRotation(CamRot[1].x, CamRot[1].y, CamRot[1].z ) All together I would do something like this instead. Once you hit a trigger, simply place the existing camera at the position and rotation of a linked camera pivot. Attach script below to a pivot. self.camera = nil --entity "Camera" self.cameraPivot = nil --entity "Camera pivot" function Script:Start() self.position = self.cameraPivot:GetPosition(true) self.rotation = self.cameraPivot:GetRotation(true) end function Script:SwitchToCameraPivot()--in self.camera:SetPosition(position) self.camera:SetRotation(rotation) end Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 7, 2017 Author Share Posted August 7, 2017 Okay Thanks. Here is a functional version of my first script with the Vec3. In case someone needs it. local CamRot = {} CamRot[1] = Vec3(0, 270 ,0) CamRot[2] = Vec3(0, 180 ,0) local CamPos = {} CamPos[1] = Vec3(5,10,-5) CamPos[2] = Vec3(-5,10,5) Cam1=1 Cam2=2 function Script:Cam1()--in self.Cam1=1 end function Script:Cam2()--in self.Cam2=2 end function Script:UpdateWorld() if self.Cam1==1 then self.entity:SetRotation(CamRot[1].x, CamRot[1].y, CamRot[1].z) self.entity:SetPosition(CamPos[1].x, CamPos[1].y, CamPos[1].z) self.component:CallOutputs("inPosition1") end if self.Cam2==2 then self.entity:SetRotation(CamRot[2].x,CamRot[2].y,CamRot[2].z) self.entity:SetPosition(CamPos[2].x,CamPos[2].y,CamPos[2].z) self.component:CallOutputs("inPosition2") end end 4 hours ago, AggrorJorn said: All together I would do something like this instead. Once you hit a trigger, simply place the existing camera at the position and rotation of a linked camera pivot. Attach script below to a pivot. self.camera = nil --entity "Camera" self.cameraPivot = nil --entity "Camera pivot" function Script:Start() self.position = self.cameraPivot:GetPosition(true) self.rotation = self.cameraPivot:GetRotation(true) end function Script:SwitchToCameraPivot()--in self.camera:SetPosition(position) self.camera:SetRotation(rotation) end Does not function. it says 1 : attempt to index global 'self' (a nil value) This would be much better because its pain to set up all the cameras in the right postion by typing coordinates. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 7, 2017 Share Posted August 7, 2017 Adjusted the script. Properties need to be declared with 'Script'. Quote Link to comment Share on other sites More sharing options...
randomdude Posted August 7, 2017 Author Share Posted August 7, 2017 Okay nice. This is working. Script.camera = nil--entity "camera" Script.cameraPivot = nil--entity "cameraPivot" function Script:Start() self.position = self.cameraPivot:GetPosition(true) self.rotation = self.cameraPivot:GetRotation(true) end function Script:SwitchToCameraPivot()--in self.camera:SetPosition(self.position) self.camera:SetRotation(self.rotation) end WIll play around with this and probably will have question again. Thank you very much. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 7, 2017 Share Posted August 7, 2017 40 minutes ago, randomdude said: WIll play around with this and probably will have question again. It is good that you are trying to make your own stuff work first. And if you are really stuck, don't hesitate to ask. That is what the community is there for. Quote Link to comment Share on other sites More sharing options...
ToniBartoli Posted February 6, 2019 Share Posted February 6, 2019 randomdude Hi, i am working on a Resident Evil like game with fixed camera angles and i was looking for a script to switch my camera with another one and i found this topic, i don't know how to use your script, can you explain me step by step how to do it, i have already 2 cameras in my room and a cube as trigger. Thank You Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.