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 Rakmo97 · Aug 25, 2012 at 04:19 AM · rotationtransformrotateflight

What's wrong with my script?

I want my camera to rotate sideways (roll) and rotate up and down (pitch). I don't know why my script doesn't work. It lets me do one or the other. But if I roll, then pitch, it does all this wierd stuff and i just don't understand. Here is my script:

 var moveSpeed:float
 
 function Update () 
 {
     if(Input.GetButton("up"))
 {
     transform.Rotate(transform.right * moveSpeed);
 }
 if(Input.GetButton("down"))
 {
     transform.Rotate(-transform.right * moveSpeed);
 }
 if(Input.GetButton("left"))
 {
     transform.Rotate(transform.forward * moveSpeed);
 }
 if(Input.GetButton("right"))
 {
     transform.Rotate(-transform.forward * moveSpeed);
 }
 }
Comment
Add comment · Show 4
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 Panik.Studios · Aug 25, 2012 at 08:44 AM 0
Share
  1. What is the intent of this script? Because there might be a better script.

  2. u can say how much u want it to rotate like this

transform.rotate = Quaternion(0,0,0,0);

(x,y,z,w)

and u would want to do some kind of $$anonymous$$athf.Lerp(Time.DeltaTime * speed); to smooth it..

avatar image Matt-Downey · Aug 25, 2012 at 11:56 AM 0
Share

transform.rotation = Quaternion(0,0,0,0) might cause a normalization error because you will divide 0 by 0 yielding Quaternion(NaN,NaN,NaN,NaN) where NaN means Not a Number.

moreover the original post said transform.rotate which doesnt exist either.

Quaternions are not euler angles.

[sorry for any perceived rudeness, I happened to just correct your question.]

avatar image Rakmo97 · Aug 25, 2012 at 12:24 PM 0
Share

I put your answer stuff in my script, and it is doing the same thing. This really just doesn't make any sence to me. Do you think it might be , like, some setting?

avatar image PitchBlackCat · Aug 25, 2012 at 12:51 PM 0
Share

I don't know if your problem is already solved, but i'd like to point you to a question i asked a long time ago: http://answers.unity3d.com/questions/50555/simple-rotation.html

The answer has a very clear explanation on how to do rotations with quarternions

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Matt-Downey · Aug 25, 2012 at 12:03 PM

The problem is you are using "Left" and "Right" and a bunch of logical but nonetheless nonexistant buttons.

Press Edit-->Project Settings --> Input and you can add "Left" and "Right" and so on if you so wish and your problem will be solved as long as you assign the buttons.

On the other hand you can do things the conventional way and use Input.GetAxis. There a four premade axes, which are "Horizontal", "Vertical", "Mouse X", and "Mouse Y". This will actually simplify your code.

 var moveSpeed:float
 
 function Update () 
 {
 transform.Rotate(transform.right, Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
 transform.Rotate(transform.forward, Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime);
 }
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 Matt-Downey · Aug 25, 2012 at 12:05 PM 0
Share

And kudos on using all the correct/logical axes for rotation. I think you might have to multiply the Input.GetAxis("Vertical") by -1, but that's it. Very nice code.

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

11 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

Related Questions

How to prevent Z axis rotation ? 1 Answer

i would like to rotate an object from an other objects script 1 Answer

Find left joystick Vector2 away from sprite's up direction. 1 Answer

I could not be more lost (rotation script) 0 Answers

How to make a bone rotate facing towards a given Transform? 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