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
0
Question by etneeko · Feb 24, 2015 at 11:45 AM · camera2.5d

Camera Rotation, Side to top-down view

Hi all, I'm creating a game and I need to use two different view points, I can do this using two cameras and a toggle switch on key press BUT this is like switching a light on and off.... I want to do this with a single camera that starts at a set point but follows the player and then with a button press the camera rotates 90 on the X and still looking at the player. the script needs to then work in reverse. I'm new to unity and this is for a uni module however we're not getting any input on how to use unity.

please help :)

Comment
Add comment · Show 1
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 Graham-Dunnett ♦♦ · Feb 24, 2015 at 11:46 AM 0
Share

Post the code you have written, and explain why it doesn't do what you want. You know how to do rotation, right? That's in the docs.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sniper43 · Feb 24, 2015 at 12:39 PM

Make the camera a child of the observed object, then simply adjust it's variables: mostlikey just transform.position and transform.rotation, or more simply just the transform.

Example code (that you will most likely copy since it should do EXACTLY what you need it to do):

 private Transform firstVP;
 private Transform secondVP;
 
 void Start()
 {
   firstVP.localPosition = new Vector3(0, 2, 0);
   secondVP.localRotation = Quaternion.Euler(0,-30, 0);
 }
 
 void Update()
 {
   if(Input.GetKeyDown(KeyCode.V))
     transform = (transform == firstVP ) ? secondVP : firstVP; //not sure if transform supports "==" operator, but here is the reference for the "?" operator in case it confuses you https://msdn.microsoft.com/en-us/library/ty67wk28.aspx
 }

Comment
Add comment · Show 4 · 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 sniper43 · Feb 24, 2015 at 12:54 PM 0
Share

In case you want more viewpoints just make a Transform array (so Transform[]) and use a counter to cycle through.

The above code would look like:

private Transform[] Viewports; private int currentViewport;

 void Start()
 {
   currentViewports = 0;
   Viewports = new Transform[2];
   //TODO, add positions/rotations here
 }
 
 void Update()
 {
   if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.V))
     transform = Viewports[currentViewports++]; //no further code needed, as ++ increase the value AFTER it has been used, alternatively use ++currentViewports to increase BEFORE it has been used> same llogic applies to --
 }

avatar image etneeko · Feb 26, 2015 at 04:06 AM 0
Share

Thank you guys, I will have a look and a play with these and I will post an update, I'm making a game at the moment for UNI and we're not getting any input other than follow the tutorials on unity and then make your own AA game........ a ga$$anonymous$$g degree in Cambridge which costs 9k a year, which can be done at home, online......

avatar image sniper43 · Feb 26, 2015 at 08:34 AM 0
Share

http://answers.unity3d.com/page/faq.html

Read through that. If you're gonna be posting new questions, you're going ot need it.

avatar image sniper43 · Feb 27, 2015 at 08:13 AM 0
Share

The above let's you cycle through preset positions, as was the original question. If you want another way to do there are way to do it, but that is irrelevant to the question, so the question should be closed.

avatar image
0

Answer by etneeko · Feb 26, 2015 at 11:01 PM

Hi sniper43, I've had a look at the first code you added on here as its in c# but I cant get it to work there are a few errors which I dont understand.

is there not an easier way to rotate the camera with a button press ?

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 sniper43 · Feb 27, 2015 at 08:10 AM 0
Share

Post these things as comments, not answers. It sitll sends me an email notification, so adding a comment > posting an answer, since answers are supposed ot be answers, not comments.

Delete this answer, and comment in what the error code is. If it is a new error because of another issue PLEASE post it as a seperate question, or search UA for an answer.

And no there isn't. Welcome to the world of software design, where computers are $$anonymous$$dless morons that can only do what you tell them to do.

avatar image etneeko · Feb 27, 2015 at 11:22 PM 0
Share

ah sorry I didnt even see the option until you pointed it out, okay so I've been working hard to get this done and I now have something that works.... It does what I need it to do however I want to tweek it but I'm at a wall now.

Okay so here is my code

using UnityEngine; using System.Collections;

public class CameraController : $$anonymous$$onoBehaviour {

 public GameObject targetObject;
 private float targetAngle = 0;
 const float rotationAmount = 1.5f;
 public float rDistance = 1.0f;
 public float rSpeed = 1.0f;
 
 // Update is called once per frame
 void Update()
 {
     
     // Trigger functions if Rotate is requested
     if (Input.Get$$anonymous$$eyDown("r")) {
         targetAngle -= 90.0f;
     } else if (Input.Get$$anonymous$$eyDown("t")) {
         targetAngle += 90.0f;
     }
     
     if(targetAngle !=0)
     {
         Rotate();
     }
 }
 
 protected void Rotate()
 {
     
     float step = rSpeed * Time.deltaTime;
     float orbitCircumfrance = 2F * rDistance * $$anonymous$$athf.PI;
     float distanceDegrees = (rSpeed / orbitCircumfrance) * 90;
     float distanceRadians = (rSpeed / orbitCircumfrance) * 2 * $$anonymous$$athf.PI;
     
     if (targetAngle>0)
     {
         transform.RotateAround(targetObject.transform.position, Vector3.right, -rotationAmount);
         targetAngle -= rotationAmount;
     }
     else if(targetAngle <0)
     {
         transform.RotateAround(targetObject.transform.position, Vector3.right, rotationAmount);
         targetAngle += rotationAmount;
     }
     
 }

}

as you can see I have getkeydown on the R and T keys for the two way rotation... so moving from one to the new and back again. I would like this all on the same key so first press does teh new rotation and then on the secend press it moves back again. I'm also finding that once my camera rotates teh player no longer moves...

Any Ideas?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Check if position is on screen 0 Answers

Art is Distorting in 2.5D Project 0 Answers

Having issues with a smooth camera follow 2 Answers

2.5D Shooter Rescrict Movement to Camera View 2 Answers

Smoother camera movement? 2 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