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 GameCherry · Feb 21, 2011 at 09:54 PM · camerarotationangles

Camera Angle Conflict Pitch & Pan...I'm Lost

Hello All,

I'm trying to customize the Smooth-Follow camera to my needs but am having trouble understanding the camera angles. My script problems is as follows:

var pitch = 30;
 function Update(){
  transform.Rotate(Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0) * Time.deltaTime * XYmousespeed);

This allows the camera to pan left and right via the mouse and works well with the camera following. The problem I'm having is setting the camera to pitch or tilt.

I added this to no avail:

transform.Rotate (pitch, 0, 0);

Obviously these two instructions conflict with each other but I cannot figure out how to make them "get along". I've tried everything I can think of but no matter what I do, I cannot get the first axis (x, I believe) to pan AND tilt - only one or the other. Any help would be greatly appreciated. Thank you for your time.

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 Bunny83 · Feb 22, 2011 at 01:17 AM

Ok, some notes in general: Input.GetAxis("Mouse ...") returns already delta values. That means it returns the amount of movement that happend in this frame. Don't use Time.deltaTime here. It would reduce the movement at high framerates and boost it on low framerates.

Now we fix the rotation. Transform.Rotate() rotates the object relative! If you call Rotate(0,0,0) nothing would change. If relativeTo is not set explicit to Space.World it defaults to Space.Self. That means you rotate you object relative to your local space.

I guess you want to rotate the camera around global y-axis and around local x-axis. This can be done with two calls to Rotate():

transform.Rotate(0, Input.GetAxis("Mouse X")*XYmousespeed, 0 ,Space.World);
transform.Rotate(Input.GetAxis("Mouse Y")*XYmousespeed, 0, 0 ,Space.Self);

An alternative would be to seperate both rotations and generate the Quaternions directly:

var Rot : Vector3 = transform.localEulerAngles;
Rot.y += Input.GetAxis("Mouse X") * RotationSpeed;
Rot.x += Input.GetAxis("Mouse Y") * RotationSpeed;
transform.localRotation = Quaternion.Euler(Rot);

ps. Don't set eulerAngles directly. They have to be within [0-360] and if you set them outside this range you will get errors.

Comment
Add comment · Show 3 · 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 GameCherry · Feb 23, 2011 at 10:02 PM 0
Share

First off, thank you for answering my question, I've been after a solution for four days. However, this didnt help me. I was looking to be able to rotate left and right with the mouse but also include a variable for the Inspector that would allow me to set the x axis up and down. Perhaps, this cannot be done? Ins$$anonymous$$d I cheated a little - I created an empty game.object as a child to my player.character and set it above and beyond my model, so my main.camera follows that ins$$anonymous$$d and it seems to work nicely.

avatar image GameCherry · Feb 23, 2011 at 10:03 PM 0
Share

I replaced my camera.orbit code with yours and it works well. I also appreciate the advice regarding Time.deltaTime and eulerAngles, I had no idea, thanks again.

avatar image Bunny83 · Feb 24, 2011 at 01:21 AM 0
Share

Thank you ;) Well, you never said that you want an orbit camera. At least i didn't read that (even between the lines). And what you did is not cheating :D that's the easiest way to do orbiting. Unity calculates everything for you and you didn't have to deal with trigonometry to adjust the cam position.

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

No one has followed this question yet.

Related Questions

Rotation around a moving object. 0 Answers

Rotation glitch with camera 1 Answer

Quaternion Slerp Sanity Check 1 Answer

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

How could I play the correct animations for a character who always rotates to look at the mouse, but takes World relative input? 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