Jump to content

Script to change camera angle


ToniBartoli
 Share

Recommended Posts

Hello,

i am working on a game in the style of Resident Evil with fixed camera angles, i actually have a room with 1 cube as trigger and 2 cameras placed at different points of view,

and actually when i start the game the first camera is active but i want the second camera become active when i hit the trigger, or maybe only one camera that change it's position when i hit the trigger.

I want to learn LUA, the problem is, there is no serious tutorial on Internet or i didn't find one yet.

Thank You

Link to comment
Share on other sites

mabye you could have only one camera in the scene, and make a pivot object with the rotation and position of the second camera. And then move the first camera to the pivot rotation and position when the player hits the trigger. And maybe store a reference to the pivot in each trigger, so that you can choose later when you have alot of camera changes

Link to comment
Share on other sites

17 minutes ago, ToniBartoli said:

@Slastraf

Thank you for your reply, indeed this is more neat to have only one camera that change position when i hit the trigger.

 

Ok now in my scene, i have only one camera, a cube as trigger and a pivot placed as the second camera, what next? How to make them working together?

if you would go to the learn section, soon you would know.

But anyway I will give you a start.

make a script on the trigger and put this at the top:

Script.pivot = nil --entity "Cam Tp Pivot" --pivot the camera teleports to
Script.enabled = true

then in the scene drag the pivot in there

now in the collision function, which is called every time something collides with it, even if its a trigger, put this:

function Script:Collision(entity, position, normal, speed)
	if self.enabled then
		if(entity:GetKeyValue("type") == "player")then
			if(self.pivot) then 
				entity.script.camera:SetPosition(self.pivot:GetPosition(true))
				entity.script.camera:SetRotation(self.pivot:GetRotation())
			end
		end
	end
end

you can read it line by line, it s pretty self explainatory. the entity in the function paramter is everything that collides with the trigger.

This would work if the camera is referenced in the player. But I dont know where your camera is in the scene, youcould use this to find it:

self.camera = world:FindEntity("Camera")

 

Link to comment
Share on other sites

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...