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 messierstudios · Apr 07, 2012 at 06:06 PM · camerarotationtransform2d platformer

2D Camera Rotation Along Level Boundaries

I'm very unfamiliar with scripting and I started learning Unity a month and a half ago. I'm working on a 2D platformer for my class and I'd love to change my camera angle from a straight side view to a slightly downward looking angle (positive rotation along the Z axis). My class has been using a lot of standard assets and prefab scripts, and for this project we've been using a slightly customized Lerpz platformer demo. I have level boundaries collider that my camera is fixed upon, moving in only the X and Y axes. Since my boundaries inform my camera movement I assume that the most straightforward way to create rotation is to input transform.rotate in the boundaries script. Is this a correct assumption, or is there a better way? And if I should transform.rotate, how would I format it within the code? Would I create a variable function or combine it with function Start? Here's the complete LevelAttributes/Boundary script:

 // Size of the level
 var bounds : Rect;
 var fallOutBuffer = 5.0;
 var colliderThickness = 10.0;
 
 // Sea Green For the Win!
 private var sceneViewDisplayColor = Color (0.20, 0.74, 0.27, 0.50);
 
 static private var instance : LevelAttributes;
 
 static function GetInstance() {
     if (!instance) {
         instance = FindObjectOfType(LevelAttributes);
         if (!instance)
             Debug.LogError("There needs to be one active LevelAttributes script on a GameObject in your scene.");
     }
     return instance;
 }
 
 function OnDisable () {
     instance = null;
 }
 
 function OnDrawGizmos () {
     Gizmos.color = sceneViewDisplayColor;
     var lowerLeft = Vector3 (bounds.xMin, bounds.yMax, 0);
     var upperLeft = Vector3 (bounds.xMin, bounds.yMin, 0);
     var lowerRight = Vector3 (bounds.xMax, bounds.yMax, 0);
     var upperRight = Vector3 (bounds.xMax, bounds.yMin, 0);
     
     Gizmos.DrawLine (lowerLeft, upperLeft);
     Gizmos.DrawLine (upperLeft, upperRight);
     Gizmos.DrawLine (upperRight, lowerRight);
     Gizmos.DrawLine (lowerRight, lowerLeft);
 }
 
 function Start () {
     createdBoundaries = new GameObject ("Created Boundaries");
     createdBoundaries.transform.parent = transform;
     
     leftBoundary = new GameObject ("Left Boundary");
     leftBoundary.transform.parent = createdBoundaries.transform;
     boxCollider = leftBoundary.AddComponent (BoxCollider);
     boxCollider.size = Vector3 (colliderThickness, bounds.height + colliderThickness * 2.0 + fallOutBuffer, colliderThickness);
     boxCollider.center = Vector3 (bounds.xMin - colliderThickness * 0.5, bounds.y + bounds.height * 0.5 - fallOutBuffer * 0.5, 0.0);
     
     rightBoundary = new GameObject ("Right Boundary");
     rightBoundary.transform.parent = createdBoundaries.transform;
     boxCollider = rightBoundary.AddComponent (BoxCollider);
     boxCollider.size = Vector3 (colliderThickness, bounds.height + colliderThickness * 2.0 + fallOutBuffer, colliderThickness);
     boxCollider.center = Vector3 (bounds.xMax + colliderThickness * 0.5, bounds.y + bounds.height * 0.5 - fallOutBuffer * 0.5, 0.0);
     
     topBoundary = new GameObject ("Top Boundary");
     topBoundary.transform.parent = createdBoundaries.transform;
     boxCollider = topBoundary.AddComponent (BoxCollider);
     boxCollider.size = Vector3 (bounds.width + colliderThickness * 2.0, colliderThickness, colliderThickness);
     boxCollider.center = Vector3 (bounds.x + bounds.width * 0.5, bounds.yMax + colliderThickness * 0.5, 0.0);
     
     bottomBoundary = new GameObject ("Bottom Boundary (Including Fallout Buffer)");
     bottomBoundary.transform.parent = createdBoundaries.transform;
     boxCollider = bottomBoundary.AddComponent (BoxCollider);
     boxCollider.size = Vector3 (bounds.width + colliderThickness * 2.0, colliderThickness, colliderThickness);
     boxCollider.center = Vector3 (bounds.x + bounds.width * 0.5, bounds.yMin - colliderThickness * 0.5 - fallOutBuffer, 0.0);
 }
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 BigBlob · Apr 07, 2012 at 06:39 PM

You don't need all this - waste of time.

Use and orthographic camera instead of perspective. It makes the objects that are still 3 Dimensional have no depth at all. Also the downward you're talking about - Change the Y Rotation to 70-90.

  • Felipe

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Move an object toward an angle in 2d space 0 Answers

Keep camera at certain distance from character when rotating 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Quaternion Slerp Sanity Check 1 Answer

How do i lock the position of the camera above the player relative to the origin point? 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