• 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 BuzzardRaze765 · Oct 09, 2019 at 09:25 AM · collision2d

How to make Camera Snaps from one area to another?

i was going to make a Camera mechanic like one in Castlevania, Megaman, etc, where your camera moves and snaps to the next Area if you enter a doorway(OnTrigger). here's how it works

 private void OnTriggerEnter2D(Collider2D collision)
     {
         if (collision.gameObject.CompareTag("Transition"))
         {
             Debug.Log(FieldIndex);
             FieldIndex++;               
             Field[FieldIndex-1].SetActive(false);
             Field[FieldIndex].SetActive(true);
             PlayerCamera.transform.position = new Vector3(Field[FieldIndex].transform.position.x, Field[FieldIndex].transform.position.y, PlayerCamera.transform.position.z);
         }

This is for the player script. the player itselfs automatically moves. and i have an array consist of 10x10 tilemaps. but the problem is it won't doing it's second transition. so when the array reaches the third field(index 2), the camera won't snap on the next field. i know there's an alternative, where you have to disable(Setactive) each camera that becomes the area's children gameobject. but i wanted to keep it only using single camera. so how to fix this?

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
0

Answer by misher · Oct 09, 2019 at 10:48 AM

Create a custom script, TransitionArea for example, attach it to the object with trigger collider. Then create empty object to represent the desired viewing position and angle when you reach the trigger, make it a child of your object. Reference its transform from your custom script, call it smt like viewPoint. Now, on trigger enter, get the script like so: collision.gameObject.GetComponen<TransitionArea>() where you can get the viewPoint and so make your camera position and rotation to match viewPoint's pos and rot. You can also implement smooth transition in a Coroutine using Vector3.Lerp and Quaternion.Slerp

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 BuzzardRaze765 · Oct 09, 2019 at 03:25 PM 0
Share

sounds complicated. but can i write this without adding a new script?

avatar image misher BuzzardRaze765 · Oct 10, 2019 at 08:20 AM 0
Share

There is nothing complicated here, it's not about making some complex new script, rather to create and organize viewing points references. It is convenient to use auxiliary transforms (empty game objects) to define your viewing point and reference them in the inspector. You can also use your scene camera to define your viewing points, move your camera in scene where you want, select your empty object and press Ctrl+Shift+F and your empty object will be set to the same position and rotation as camera.

Explain better in detail how do you want to setup your transitions, so we can come up with better design.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

112 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

Related Questions

Disappearing platform problem - RigidBody2D and BoxCollider2D 0 Answers

Creating an infinite trail that can be collided with 2 Answers

Physics2D Mesh Collider? 1 Answer

Collision 2D doesnt work 0 Answers

problem Getting AI projectile to collide with player 0 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