Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Ouija · Nov 07, 2012 at 05:04 AM · cameratriggersmultipleswitchhorror

Switching Several Cameras(HorrorGame)

Hey guys, my question should be simple hopefully. I have a level done, with 5 cameras set up at different positions and angles. The best way to describe what I am going for would be like how the camera switches nice and clean like in older horror games. Silent hill for example with all the amazing angels.

So right now, I have the 5 cameras with 5 boxes for triggers to be touched by the player. i know triggers and such are needed, but im not sure on how to write code just yet. C# or Java doesn't matter. Either seems fine. Any ideas? Seems simple but I just don't know where to start!

searched other questions but i cant find any that deal with multiple cameras switching by triggers.

Other advice is welcome! whatever it takes to get it done.

Check out my profile icon! thats my character for the game, hopefully it will inspire someone to help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by AlucardJay · Nov 07, 2012 at 06:33 AM

So I have been thinking about this, and may have a flexible approach.

Each camera is a component or child of your trigger object. So tell the camera to enable when the trigger is entered. But then there is the problem of turning the old camera off. Just store a reference to the currently used camera, and when the trigger enables a new camera, then disable the stored one, then make sure to store a reference to the new current camera.

Here is some rough untested code to try and explain the theory. The idea then is no matter how many cameras there are, this should keep working (as long as the trigger volumes are not too close together). Adding or removing cameras and trigger volumes becomes fun, not a hassle with rewriting code =]

 // -- PLAYER SCRIPT --
 #pragma strict
 
 // FOR MULTIPLE CAMERAS
 public var currentCam : Camera;
 
 function Start() 
 {
     // Enable the first camera
     currentCam = Camera.allCameras[0];
     // disable all other cameras
     for ( var i:int = 1; i < Camera.allCameras.Length; i ++ )
     {
         Camera.allCameras[i].enabled = false;
     }
 }
 
 // ----
 
 // -- TRIGGER SCRIPT --
 #pragma strict
 
 var thePlayerScript : PlayerScript;
 var myCamera : Camera;
 
 function Start()
 {
     // find myCamera (child or component of trigger object)
     myCamera = transform.parent.FindChild( "Camera" ).GetComponent( Camera );
 
     // find the Player, store reference to player script
     // to use .enabled = false; when switching cameras
     thePlayerScript = GameObject.FindWithTag( "Player" ).GetComponent( PlayerScript );
 }
 
 function OnTriggerEnter( other : Collider )
 {
     // disable current camera
     thePlayerScript.currentCam.enabled = false;
 
     // enable this camera
     myCamera.enabled = true;
 
     // assign this camera as the current camera
     thePlayerScript.currentCam = myCamera;
     
     Debug.Log( transform.parent.gameObject.name + " Triggered by " + other.gameObject.name );
 }


Any feedback is most welcome =]

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Nov 07, 2012 at 06:41 AM 0
Share

The character looks great ! But I was inspired by being re$$anonymous$$ded of Resident Evil 3 =]

avatar image AlucardJay · Nov 07, 2012 at 10:36 AM 0
Share

I don't have lerpz, isn't that a 2D tutorial?

If you can take a screenshot of the scene, with the character highlighted and the inspector showing, and edit your question, post the picture so I can see what the lerpz character is. Or just clarify the name of the tutorial so I can download the lerpz character and check it out. It should be no problem to make work, maybe some fancy swapping of tags, or just assigning currentCam to the lerpz script. Pass on the extra info, did you just use my code as it is? wow it worked!

Edit : Just looking at the scripts involved in the 2D Lerpz and the camera target stuff, it seems next to impossible to just mash it together with a camera system like you have designed.

avatar image AlucardJay · Nov 07, 2012 at 02:16 PM 0
Share

The theory works : http://www.alucardj.net16.net/unityanswers/ResEvilCameras.html

As I said above, the problem will be making a hybrid of the Lerpz camera system and your multiple camera system.

avatar image Ouija · Nov 07, 2012 at 10:44 PM 0
Share

The NEW update to your script works perfectly!! Amazing! Thanks alot man Il give it thumbs up now :)

Edit: The cameras do indeed switch, BUT I dont think they turn off, while looking at the inspector, it shows the all cameras still being on, and there is a strong leg as you move from camera to camera cause of it, what could it beee H$$anonymous$$$$anonymous$$$$anonymous$$ lol

avatar image AlucardJay · Nov 08, 2012 at 02:58 AM 0
Share

Thanks for the comments =]

The controls are so basic they shouldn't be called controls ! It was just to have something that hit the triggers. But this is how Resident Evil worked, your controller forward moved the character forward to how the character is facing, not how the camera is facing. SO if you were walking forward away from a camera then the camera swapped, pusing forward would still walk forward so the character would move towards the new camera. For controls that move the charater the way the camera is facing, I did an answer here : http://answers.unity3d.com/questions/318305/character-controls-like-the-game-fable.html

Thanks, I like to think I'm legit, but ama self-taught noob and only a programmer, not an artist. I like to help people too. That Ghosthunter game I did in Feburary, 1 month after starting Unity. The music player is broken so every restart there is an extra music player. I actually removed it but someone asked me to put it back, so it is there to show what can be done by a new user =] I do want to fix it, but with all I have learned I am simply going to rewrite it. I am proud that all the objects are Unity natives, even the turkeys!

The image you sent looks good, the game should turn out neat. But unfortunately without seeing the trigger volumes (like i did with the transparent red material) I cannot see the volumes, the area they affect or more importantly if they are overlapping or too close.

I found the 3D tutorial (thanks for the link, i was thinking of lerps here : http://unity3d.com/support/resources/tutorials/2d-gameplay-tutorial), so am about to unzip and look at the character controller.

WIth your issue with more than one camera, I actually wrote a Start function on the player to disable all cameras and then just turn the first one on. Then as a trick, I put the character just above the triggere where the player starts, so on Play, character falls to the floor, activating the trigger and automatically setting the correct camera to be the first used camera. All other cameras have to be disabled, here is my function I used :

 // FOR $$anonymous$$ULTIPLE CA$$anonymous$$ERAS -- ResEvil
 public var currentCam : Camera;
 
 function Start() 
 {
     // Enable the first camera
     currentCam = Camera.allCameras[0];
     // disable all other cameras
     for ( var i:int = 1; i < Camera.allCameras.Length; i ++ )
     {
         Camera.allCameras[i].enabled = false;
     }
 }
 

I don't know what else to suggest without looking at the 3D lerpz controller, but as in the demo the trigger volume multi camera system works (as long as there is only ever one camera enabled!). If I find anything out or make a demo project with the Lerpz char, I shall post back. Good Luck.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Camera.main.ScreenPointToRay 1 Answer

Add multiple cameras problems 1 Answer

Switching cameras with the mouse button 1 Answer

UI Buttons switch cameras 3 Answers

Main Camera Switch? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges