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
1
Question by Qasem2014 · Mar 01, 2015 at 07:27 AM · cameraplayerrange

Simple Problem With Rotation !!!

hi , i have a player game object that have a camera as child . and i have a camera controller script like this :

 if(MyCamera.transform.rotation.x < 0.25)
 {
     if(RTD == true )
     MyCamera.transform.rotation *= Quaternion.Euler(20*Time.deltaTime,0,0);
 }
 if(MyCamera.transform.rotation.x > -0.25)
 {
     if(RTU == true )
     MyCamera.transform.rotation *= Quaternion.Euler(-20*Time.deltaTime,0,0);
 }

MyCamera is the camera and RTD/RTU (boolean variables) is checking the rotation button is hold or not .

problem is i cant limit rotation to up and down between a range (if statement is useless) , because Quaternion.Euler reset the X rotation to 0 every time i hold the rotation button . i use this code before :

 MyCamera.transform.Rotate(-Time.deltaTime*20,0,0);

it also not work and i don't know why ! i also use this code :

 if(MyCamera.transform.rotation.x > -0.25)
 {
     if(RTU == true )
     MyCamera.transform.rotation.x -= 0.01;
 }

it works fine but when i rotate the player ( camera is child of it ) to left/right , camera rotating in wrong way (not rotate in x but rotate in x and y or x and z) !!!!!!

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 VipHaLongPro · Mar 01, 2015 at 07:04 PM 0
Share

Looks like this kind of question requires some real test. Also it seems that no one could know exactly what it is. In the first place, you use *= with 20*Time.delta which is very small, the x could be rounded down to 0. So it's always 0. Try using += ins$$anonymous$$d. Even with that the camera can go in wrong direction as you said in the last sentence. I doubt that may be related to using transform.rotation while it should be transform.localRotation. That's my suggestion, you should give it a try. I hope you'll comment back the result soon.

3 Replies

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

Answer by Qasem2014 · Mar 06, 2015 at 06:29 PM

i asked it differently in THIS link . and problem Solved :)

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 lordlycastle · Mar 01, 2015 at 06:58 PM

I think it's because you are limiting the rotation between -0.25, and 0.25 degrees which is very small. An average Time.deltaTime is about 0.015 s; and 20 * 0.015 = 0.3, so it rotates just once and you cannot notice it.

Try using RotateAround() instead of just setting the rotation manually. Set the axis argument equal to the y-axis (or according) to your character.

What are RTU, and RTD variables, and when do they change. A few things, use else if{} if it's two mutually exclusive statements. Also you can combine the nested if statements like _myCam.Transform.Position > -0.25 && RTU == true.

Comment
Add comment · Show 1 · 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 Qasem2014 · Mar 02, 2015 at 06:25 PM 0
Share

camera is a child of player game object ! i use RotateAround() before and it work not fine (camera go to another position) ! i think because of its a child of player .

avatar image
0

Answer by sparkzbarca · Mar 01, 2015 at 07:11 PM

hmmm i'm just going to give you some code that works to limit rotation :P

     if (Input.GetButton ("Rotate Camera")) {
         RotateAngle += Input.GetAxis("Mouse Y");
         RotateAngle = Mathf.Clamp(RotateAngle, MinX,MaxX);
         CamTransform.RotateAround (CamTransform.position, Vector3.up, Input.GetAxis ("Mouse X"));
         CamTransform.rotation = Quaternion.Euler( new Vector3(-RotateAngle ,CamTransform.rotation.eulerAngles.y,CamTransform.rotation.eulerAngles.z));
     }

define these variables

RotateAngle, should be a vector3

MinX, should be minimum angle, -60 works well

MaxX, should be max angle, 60 works well

if you need help post whats wrong.

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 Qasem2014 · Mar 02, 2015 at 06:20 PM 0
Share

what is RotateAngle += Input.GetAxis("$$anonymous$$ouse Y") ? what it do ?

i have ui button (its for mobile) . what is I*nput.GetAxis ("$$anonymous$$ouse X") in CamTransform.RotateAround* ??

avatar image Qasem2014 · Mar 04, 2015 at 05:30 PM 0
Share

TELL $$anonymous$$E U CAN HELP $$anonymous$$E $$anonymous$$ORE :(( TELL $$anonymous$$E :((

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

23 People are following this question.

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

Related Questions

Animation automatique personnage 0 Answers

Locking world rotation of child 1 Answer

3d Sound when the player near and not the camera? 1 Answer

Walk animation for camera isn't playing 1 Answer

How you change another script value smoothly on trigger 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