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 devstudents · Sep 13, 2014 at 02:20 PM · camerarotationorthographic

How to rotate around the centre of screen on the Y axis in othrographic

I asked this in another post but could not post anymore on that page so I've started a new topic!

I am trying to rotate on Y around the centre of the screen in othographic mode. I do not want any tilt whatsoever (I'm going for a 3d isometric theme). The problem is that the rotation goes in a large circular arch and the centre screen is lost until the rotation is complete.

I was given advice to make the script holding parent of the camera the centre of the camera viewpoint from the get go. This worked initially but as soon as I moved the parent, the camera would go on these large circular rotations and the original centre of the screen would be lost from sight.

I've attached the code I'm using. It's cobbled together from various tutorials and has some of my own additions. My camera is in orthographic, its positioned so the parent is in the centre, the script is attached to the parent, and near clipping is set to -100.

Hope that is enough info! Ideally I would love to find a way for the camera to stop blurring when it moves.... but maybe I shouldn't get greedy in this post ;)

 using UnityEngine;
 using System.Collections;
 
 public class IsometricCamera : MonoBehaviour 
 {
     //camera move speed
     public int cameraSpeed; 
     
 
     // Update is called once per frame
     void Update () 
     {
         //translating on the x, z and Y axes using WASD
 
     if(Input.GetKey("w"))
         {
 
             transform.Translate(Vector3.up * cameraSpeed * Time.deltaTime ); 
         }
 
         if(Input.GetKey("s"))
         {
             
             transform.Translate(Vector3.down * cameraSpeed * Time.deltaTime ); 
         }
 
         if(Input.GetKey("d"))
         {
             
             transform.Translate((Vector3.right + Vector3.back) * cameraSpeed * Time.deltaTime); 
         }
 
         if(Input.GetKey("a"))
         {
             
             transform.Translate((Vector3.left + Vector3.forward)  * cameraSpeed * Time.deltaTime ); 
         }
 
         //zooming up and down with the scrollWheel
 
         GameObject isoView = GameObject.Find("Main Camera");
         if(Input.GetAxis ("Mouse ScrollWheel") > 0 && isoView.camera.orthographicSize > 2)
         {
             isoView.camera.orthographicSize = isoView.camera.orthographicSize - 1; 
         }
 
         if(Input.GetAxis ("Mouse ScrollWheel") < 0 && isoView.camera.orthographicSize < 20)
         {
             isoView.camera.orthographicSize = isoView.camera.orthographicSize + 1; 
         }
 
         //rotate
 
         if(Input.GetKey("e"))
         {
             transform.Rotate(Vector3.up * cameraSpeed * Time.deltaTime, Space.World); 
         }
 
         if(Input.GetKey ("q"))
         {
             transform.Rotate(Vector3.down * cameraSpeed * Time.deltaTime, Space.World); 
         }
 
     }
 
 }
 
 
 
 
 
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 sevensixtytwo · Sep 13, 2014 at 02:46 PM

Hmmm. What kind of isometric camera are you working on? I'm unsure of what your code would do since you have

  transform.Translate((Vector3.right + Vector3.back) * cameraSpeed * Time.deltaTime); 

...which makes it odd that you also have Vector3.up and Vector3.down there. Unless we're talking non-Euclidean geometries here. xD

Try this. It's derived from a top-down isometric camera I did for school.

 if(Input.GetKey("w"))
         {
  
             transform.Translate(transform.forward * cameraSpeed * Time.deltaTime ); 
         }
  
         if(Input.GetKey("s"))
         {
  
             transform.Translate(-transform.forward * cameraSpeed * Time.deltaTime ); 
         }
  
         if(Input.GetKey("d"))
         {
  
             transform.Translate(transform.right * cameraSpeed * Time.deltaTime); 
         }
  
         if(Input.GetKey("a"))
         {
  
             transform.Translate(-transform.right  * cameraSpeed * Time.deltaTime ); 
         }

 if(Input.GetKey("e"))
         {
             transform.Rotate(transform.up * cameraSpeed * Time.deltaTime); 
         }
  
         if(Input.GetKey ("q"))
         {
             transform.Rotate(-transform.up * cameraSpeed * Time.deltaTime); 
         }

Put it on an empty gameObject at position (0,0,0) and rotation (0,0,0). Then parent a camera to it with position (-18.371,15,-18.371) and rotation (30,45,0).

It should look like a Diablo 1/2 style camera and moves relative to its own rotation. Even if you rotate it, it will move in the local forward.

Comment
Add comment · Show 9 · 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 devstudents · Sep 13, 2014 at 09:15 PM 0
Share

Thanks a lot for your answer. You fixed my rotation problem but the style of movement is something I tried very hard to change before. When I move up I want the camera to go directly up (not north west), and when I go right or left, I want it to go perfectly east and west respectively in relation to the screen view. This is why I have that peculiar line of code (that gives me crappy rotation). It's the only way I found to make sure that the camera pans properly. Also, when I do rotate it, I want s to still take me down in relation to the screen and not up etc. Using your code gave me great rotation but all the controls effectively become switched when I do rotate.

The camera view I'm trying to emulate is found in games like Timber and Stone and Anno 1404. Any ideas?

avatar image sevensixtytwo · Sep 14, 2014 at 12:53 AM 0
Share

I see. So the camera should go directly north, south, east and west in relation to the camera, yes? Not sure about your problem with the controls switching though. Tell me more about it.

In the meantime, try setting the parent to rotations (0,45,0) and the camera's transforms to positions (-2.109775e-06,15,-25.98076) and rotations (30,0,0). See how it works.

avatar image devstudents · Sep 14, 2014 at 05:20 PM 0
Share

Not having much luck. The script I had first is still the only one that moves as I want it to move, but your one is still the only one that rotates in the desired fashion -even though if I rotate the parent then the WASD keys move the parent according to it's position and not the viewpoint of the screen. I hope that made sense. I am very new to vectors!!!

Thanks so much for the suggestions by the way! Is there any way I can send you a basic unity file with the scene, code, camera etc? I'm not sure if pas$$anonymous$$ll can take something like that.

avatar image sevensixtytwo · Sep 15, 2014 at 01:33 AM 0
Share

That'd be great. You can pack the most relevant files in a unitypackage. I'm guessing a scene with a few primitives and one script wouldn't be too big to attach to a comment or something.

avatar image devstudents · Sep 18, 2014 at 05:07 AM 0
Share

hey sorry for the late reply! I'm not getting notified for some reason (sometimes it does notify me but it seems to be quite sporadic!).

I'm having a bit of trouble uploading a package to unity answers. It says the file type is not valid. Do you need unity pro to successfully export a package? I followed the steps on how to make a package and it seemed pretty straight forward. The best I can do is this link to my good drive:

https://drive.google.com/file/d/0B4OAxw1eGEZ4Q0ZOcGR$$anonymous$$cDFHNWc/edit?usp=sharing

hope it works!

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

2 People are following this question.

avatar image avatar image

Related Questions

Orthographic Camera rotation on world y-axis but also rotates z-axis slightly? 0 Answers

Using a perspective camera can an object act as if viewed by orthographic camera? 1 Answer

How to freeze the rotation or the position on the camera transform? 1 Answer

how do i make first person character rotate left and right along with camera? 0 Answers

Orthographic camera movement clamping 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