• 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 /
  • Help Room /
This question was closed Jan 10, 2016 at 12:08 PM by oen432 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by oen432 · Jan 09, 2016 at 04:54 PM · rotation axisz axis

Rotate on Z axis forward and backward.

Hi,

I'd like to know how to properly rotate on Z axis. To be more specific, it should work like this:
Rotate forward (object lean forward) and Z axis is getting bigger from 0.
Rotate backward (object lean backward) and Z axis is getting smaller from 0.

Why I ask? Here is my code that I'm using to rotate.

 if(Input.GetKey(KeyCode.W)) {
     transform.Rotate(-Vector3.forward * Time.deltaTime * 20.0f, Space.Self);
 }
 else if(Input.GetKey(KeyCode.S)) {
     transform.Rotate(Vector3.forward * Time.deltaTime * 20.0f, Space.Self);
 }

That's all. But when I'm holding W key, Z axis is starting at 360 and getting lower but holding S key is working properly (almost) but it starts at 0 and getting higher, 1, 2, 3 etc. I'd like to add that in Scene when I'm rotating, Z axis is working properly.

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

  • Sort: 
avatar image
1

Answer by Fattie · Jan 09, 2016 at 07:36 PM

Use this ..

 Transform.Rotate( 0f, 0f, 3.5f );

where it says "3.5f put in whatever value you want.

Comment
Add comment · Show 4 · 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 oen432 · Jan 09, 2016 at 07:38 PM 0
Share

Can't do this. I have to change Z axis over time, not just set a value.

avatar image Fattie oen432 · Jan 09, 2016 at 07:43 PM 0
Share

You misunderstand the command Transform.Rotate. I can absolutely assure you your'e looking for Transform.Rotate.

avatar image oen432 Fattie · Jan 09, 2016 at 07:52 PM 0
Share

Still nothing.

 if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) {
         transform.Rotate(new Vector3(0.5f, 0f, 0f));
     }
     else if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.S)) {
         transform.Rotate(new Vector3(-0.5f, 0f, 0f));
 }


avatar image KUFgoddess · Jan 15, 2017 at 10:47 AM 0
Share

what if on void Start (){ Transform.Rotate( 0f, 0f, 3.5f ); } you wanted it to automatically lerp between two variables or floats? like 0 and 0.3f Like if you're trying to create a flying object and your want a little bit of smooth automated rotation.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

32 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can we change Z direction so that 2D renders Back to Front ? 0 Answers

Bugs, bugs and bugs again! 0 Answers

have enemy try to get in front of player and push them back help 0 Answers

How to make the object return to its last angle (before the angle limit) go back no so abruptly ? 0 Answers

How can I flip a player over the Horizontal and Vertical axis? 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