Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 knifeyau · Dec 22, 2016 at 10:51 AM · camerarotatecamera-movementcamera rotateeulerangles

How to rotate my camera?

I just want to get my head around the basics. As soon as I use player.transform.Rotate to turn the player, the camera while using eulerAngles orbits the player. Can I compensate for this?

     x += Input.GetAxis ("Mouse X");
     x = Mathf.Clamp (x, -4, 4);
     y += Input.GetAxis ("Mouse Y");
     y = Mathf.Clamp (y, -12, 20);

     player.transform.Rotate (0, x , 0);
     x = 0;
     transform.eulerAngles = new Vector3(y + mouseYOffset, 0, 0);

Because eulerAngles works perfectly (moving the cam up and down) when I comment out the Rotate part I'm guessing it's stuffing up because the camera is a child of the player and the rotation of the player is moving? If I use rotate instead of eulerAngles I have to put in if (angle > limit) { things to stop the player moving outside the bounds of the camera, which eulerAngles lets me use Mathf.Clamp... seems far better. So if anybody can help me get it to actually work that would be great :)

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 srikaran_p · Dec 22, 2016 at 10:53 AM 0
Share

It seems you are making a FPS controller. Use the Standard Assets ins$$anonymous$$d as it has better camera movement.

2 Replies

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

Answer by knifeyau · Dec 22, 2016 at 04:31 PM

x = 0;

x += Input.GetAxis ("Mouse X");

x = Mathf.Clamp (x, -4, 4);

y += Input.GetAxis ("Mouse Y");

y = Mathf.Clamp (y, -12, 20);

player.transform.Rotate (0, x, 0);

transform.eulerAngles = new Vector3(player.transform.eulerAngles.x + y,

player.transform.eulerAngles.y, 0);

Grabbing the eulerAngles from the player and using them to offset the camera was the answer. Just figured it out on my own.... so I thought I would share this solution for anybody looking in the future.

~Knifey

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 ImFromTheFuture · Dec 22, 2016 at 01:06 PM

I had to write my own rotation script and this is what I came up with. You should modify this to suit your needs:

 float rotDirection = 1;
 public float rotSpeed, minAngle, maxAngle; // Angle clamps
 public Transform target; // The gameobject you want to move
 
 void Update {
 
     float dX = Input.GetAxis ("Mouse X");
     float dY = Input.GetAxis ("Mouse Y");
 
     rotX += dY * rotSpeed * -rotDirection * Time.deltaTime;
     rotY += dY * rotSpeed * rotDirection * Time.deltaTime;
 
     if (rotX > 180) 
         rotX = rotX - 360;
         
     rotX = Mathf.Clamp (rotX, minAngle, maxAngle);
 
     target.eulerAngles = new Vector3 (rotX, rotY, 0f);
 
 }
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

Return camera to original rotation values Logic 1 Answer

3rd Person Orbit Camera in LOCAL Space 0 Answers

Rotate Camera to the object 0 Answers

How to have free rotation camera? 1 Answer

camera movments fixed.. character controller without using character controller -.-' 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