Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by $$anonymous$$ · Jul 12, 2018 at 02:43 AM · cameracollisionobjectchange

How can I change camera when colliding with "X" object?

Hi, I'm new to Unity, I'm trying to make a Sonic Fan-game but I don't know programation (I know I should have that knowledge if I want to create a game, I'm sorry). The thing is that I want to change to "B" camera (Or the angle of the main one) by entering to "X" object and go back to "A" camera by exiting "X" object

alt text

As you can see, I have a "Loop de loop" in here and I want to change the camera angle so the player doesn't have any problem by seeing where they going while they're running throught it.

(Also, English is not my mother language, if there are any orthographical errors is because of that)

captura.png (80.5 kB)
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
1
Best Answer

Answer by ModLunar · Jul 12, 2018 at 03:41 AM

One possibility is having a trigger collider to cover the entire ramp's volume -- so you can detect the player getting on/off the ramp. So you can create an empty GameObject somewhere around the center of the ramp. You can add a Collider to that new object (say a BoxCollider or SphereCollider for example), and mark "Is Trigger" to true (checked) in their inspector. Marking a Collider as a trigger will make it not a physical collider that pushes you, but instead, it becomes one that can detect other Colliders entering/leaving its volume.

So if you have that trigger Collider, you can create a new MonoBehaviour C# script and attach it to the same GameObject. In that C# class, you can create methods to catch Unity's special "messages". Just like Awake(), Start(), and Update() are magically called from Unity for you, you can define methods called "OnTriggerEnter", "OnTriggerStay", and "OnTriggerExit". These give you information about other Colliders entering and leaving its volume. More specifically, here's the signature of those methods:

 //Gets called when a Collider enters the trigger's volume
 public void OnTriggerEnter(Collider other) {
     
 }
 
 //Gets called every physics update where another Collider is still inside the trigger's volume
 public void OnTriggerStay(Collider other) {
     
 }

 //Gets called when a Collider leaves the trigger's volume
 public void OnTriggerExit(Collider other) {
     
 }


The argument given to each of the method, "Collider other", is the other Collider that has come into contact or lost contact with the current trigger Collider. so maybe you can have an if statement to ask if the other Collider belongs to the player's GameObject. If that is so, then you can make the currently active Camera disabled and enable the Camera for the ramp -- something like this:

 public class RampTriggerVolume : MonoBehaviour {
     public Camera normalCamera;
     public Camera rampCamera;
 
     public void OnTriggerEnter(Collider other) {
         //When the player gets close enough (into this trigger's volume)
         //then we turn on the ramp Camera and temporarily turn off the normal one
         if (other.gameObject.tag == "Player") {
             SwitchToRampCamera();
         }
     }
 
     public void OnTriggerExit(Collider other) {
         if (other.gameObject.tag == "Player") {
             SwitchToNormalCamera();
         }
     }
 
     private void SwitchToRampCamera() {
         rampCamera.enabled = true;
         normalCamera.enabled = false;
     }
 
     private void SwitchToNormalCamera() {
         rampCamera.enabled = false;
         normalCamera.enabled = true;
     }
 }
 


This script/class (which I called "RampTriggerVolume") will switch the cameras immediately if the trigger detects that a Collider, attached to a GameObject that has the tag "Player" in the inspector, enters/exits its volume. Hopefully this is enough to get you started!

And by the way, to use this RampTriggerVolume script, drag the script onto the same GameObject as the trigger Collider. You should also add a Rigidbody component marked as "Kinematic" (isKinematic should be true). Two Colliders will ignore each other if neither of them have a Rigidbody -- at least 1 of them need a Rigidbody for the "OnTriggerXXX" events to get called. Being Kinematic will make the ramp's trigger Collider not actually receive forces, so it will stay fixed in place (unless you have your own scripts moving it or something)

P.S. - Your English is pretty good! Probably better than I would be able to do in your language xD bravo for trying!

Comment
Add comment · Show 2 · 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 $$anonymous$$ · Jul 12, 2018 at 09:51 PM 1
Share

Thank you so much! It worked!

avatar image ModLunar $$anonymous$$ · Jul 12, 2018 at 09:52 PM 0
Share

Yay ^_^ I'm glad to help, you're welcome!

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

180 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

enable disable objects when objects collides with other object 1 Answer

How do I get rid of white lines when objects collide? 1 Answer

import google sketchup collision 1 Answer

Object pool shooting not working 0 Answers

How to keep player in screen? 1 Answer


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