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 mythraend · May 28, 2012 at 07:31 PM · camerarotationset

Setting Main Camera Rotation

I can't figure out how to set the rotation of the camera to an exact set of x,y,z values using C#. Once I realized that transform.position could set the position in a similar way to using the inspector, I figured it would be just as easy for the rotation. I need to set the camera for multiple positions for an rpg (map, third person, first person etc). I figured I save a flowing move of the camera for later. Any help would be greatly appreciated.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by whydoidoit · May 28, 2012 at 07:32 PM

Don't worry, it's very simple:

   Camera.main.transform.rotation = Quaternion.Euler(x,y,z);

There's some smooth move stuff on my blog - http://www.whydoidoit.com - smoothed quaternions, moving on a path - but that ain't rocket science either :)

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 mythraend · May 30, 2012 at 01:50 AM 0
Share

Thanks, that worked, I can zap the view point around in the unity asset dungeon (the coolest thing I've done in unity). I checked out your blog and found the "Path $$anonymous$$ove and Character Speed" section. This looks like what I might need to move the character forward to the door. So, I'll look into what a Spline, a path and the currently targeted path point is and see if I can figure out how to impliment it.

avatar image whydoidoit · May 30, 2012 at 01:58 AM 0
Share

Well that move on path will move between a number of locations in a smooth manner, kind of controlled - I use it to move cameras on switchable tracks.

The smooth stuff is just a wrapper around a bunch of functions that you can call directly like Lerp and smoothdamp which make normal movements less jerky.

avatar image
1

Answer by hockey77 · Apr 11, 2020 at 09:06 PM

currentRotation.x += Input.GetAxis("Mouse X") sensitivity; currentRotation.y -= Input.GetAxis("Mouse Y") sensitivity; currentRotation.x = Mathf.Repeat(currentRotation.x, 360); currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle); Camera.main.transform.rotation = Quaternion.Euler(currentRotation.y,currentRotation.x,0); if (Input.GetMouseButtonDown(0)) Cursor.lockState = CursorLockMode.Locked;

That could be the answer:D

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 joedt100 · Sep 11, 2017 at 05:46 PM

@whydoidoit This doesn't work for me as when I try to set exact rotations for the camera it doesn't do anything at all.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Quaternion Slerp Sanity Check 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

Override Oculus Orientation 5.3 1 Answer

How to make the camera rotate only when right click is held down on the mouse? 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