Jump to content

Switchable static Camera


randomdude
 Share

Recommended Posts

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.

lw.png

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 year later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...