• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Oct 22, 2014 at 07:23 PM · camera3d-to-2d

rotate camera

Hello Unity3D i have a question about my camera.How can i code my camera to rotate to look at my player from a 2D view whenever i hit something or someone?Something like a 90 degree angle and when i run back or forward its back to a 3d view?If anyone knows how i can do this.Can you please tell me how this could be done?For some reason i can't find it.

Comment
Add comment · Show 2
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 Dimling · Oct 22, 2014 at 07:42 PM 0
Share

Not sure if I understod the question, but maybe lerp is the thing you are looking for? In this tutorial its used on a light source, but it might as well be used on a camera:

Unity Official Tutorial: Lerp

avatar image robertbu · Oct 22, 2014 at 07:58 PM 0
Share

You need to provide more information about your setup before we can give you an accurate answer. And seeing your current tracking code would be very helpful as well. In particular we need the frame of reference. That is, is the 2D view relative to world space (i.e. the player and the camera would have the same x,y values for a 2D view), or is the 2D view relative to the character (i.e. the camera would be directly to the right of the player). And what defines the distance the camera is away from the player?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by drudiverse · Oct 23, 2014 at 02:23 PM

you can set a quaternion variable that is a 2d rotation relative to the player i.e. based on, var = player position(x,y,z-10), that you want for all the collisions in 2d, and use slerp to rotate the camera to that rotation in a time given, and then slerp back to the 3d view when you want, and the switch off the slerp function when it's back in 3d. all it would need is

rotation = slerp(2drot,3drot,value from 0 to 1 to choose which rot);

that will only change the rotation of the camera correctly,

to also change it's position in an arc around the player, you can place an invisible dot behind the camera, and then you can do

 camera.transform.position = player position + (camerapos-invisibledotpos)*distance

or even

 camera.transform.position = playerpos-camera.transform.forward*distancevar;

that will place the camera always facing the player whatever rotation it is at, at the same distance.

Comment
Add comment · 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
0

Answer by IKilledKenny_2 · Oct 23, 2014 at 09:40 PM

Sorry This is The Script If anyone is still interested #pragma strict var targetPos : Transform; var lookAtObj : Transform; // smooth damp stuff

 private var targetVX : float;
 private var targetVY : float;
 private var targetVZ : float;
  
 var targetSmoothDamp : float = 0.3;
 var targets: GameObject[];
 targets = gameObject.FindGameObjectsWithTag("Player");
  
 function Start () {
  
 }
  
 function Update () {
  
 transform.position.x = Mathf.SmoothDamp(transform.position.x, targetPos.position.x, targetVX, targetSmoothDamp);
 transform.position.y = Mathf.SmoothDamp(transform.position.y, targetPos.position.y, targetVY, targetSmoothDamp);
 transform.position.z = Mathf.SmoothDamp(transform.position.z, targetPos.position.z, targetVZ, targetSmoothDamp);
  
  
  
 transform.LookAt(lookAtObj);
 }
Comment
Add comment · 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

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

29 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

Related Questions

A node in a childnode? 1 Answer

make android camera video as the background of the unity scene? 0 Answers

Camera Animation 1 Answer

Unity shadows work in scene, but no through camera 0 Answers

Mouse scroller problem 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