• 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 Emanrice · Jun 22, 2011 at 09:11 PM · rotatetype

Object not rotating

Hi, I have this script here:

 var speed = 2;
 var rot = 0;
 function Update () {
     rot += Input.GetAxis("Horizontal")*speed *Time.deltaTime;
     var z = Input.GetAxis("Vertical")*speed *Time.deltaTime;
     transform.Translate(0,0,z);
     transform.Rotate(0,0,rot);
 }


What it's supposed to do is rotate the object if you press left or right, and also move it if you press up or down. The problem is the object won't rotate. I've added a print(rot) after the transform.Rotate line, but it always prints a 0. What am I doing wrong?

Comment
Add comment · Show 5
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 flaviusxvii · Jun 22, 2011 at 09:12 PM 0
Share

I fixed your code formatting. $$anonymous$$ake sure to format properly in the future.

avatar image Emanrice · Jun 22, 2011 at 09:16 PM 0
Share

Sorry about that, I didn't see any button or anything to format it though.

avatar image Anxo · Jun 22, 2011 at 09:18 PM 0
Share

Does your Z value change?

avatar image Anxo · Jun 22, 2011 at 09:18 PM 0
Share

for your movement I mean

avatar image Emanrice · Jun 22, 2011 at 09:19 PM 0
Share

Yes it does. The object can move correctly, just not rotate.

2 Replies

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

Answer by Eric5h5 · Jun 22, 2011 at 09:19 PM

You made "rot" an int, and are trying to add a fraction to it, so it will always remain 0. Also, unless you meant that the rotation speed should continuously increase the longer you rotate, you should do it this way:

 var speed = 2.0;
 
 function Update () {
     var rot = Input.GetAxis("Horizontal")*speed *Time.deltaTime;
     var z = Input.GetAxis("Vertical")*speed *Time.deltaTime;
     transform.Translate(0,0,z);
     transform.Rotate(0,0,rot);
 }
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 aldonaletto · Jun 22, 2011 at 09:27 PM 0
Share

One more thing: Rotate parameters are in degrees, so your character will rotate 2 degrees/s, which is very slow. Specify a different speed for rotation (30 to 60 works fine).

avatar image Emanrice · Jun 22, 2011 at 09:31 PM 0
Share

I had just noticed that.

avatar image flaviusxvii · Jun 22, 2011 at 09:47 PM 0
Share

Stupid implicit types. They'll get you every time!

avatar image
-1

Answer by Emanrice · Jun 22, 2011 at 09:30 PM

It works! Thanks for the help! EDIT: Shouldn't this be below your reply?

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 Chris D · Jun 22, 2011 at 09:44 PM 1
Share

The Unity Answers system doesn't allow you to comment on other people's answers until you hit a rep threshold. In the future, you can either add comments to your original post or edit your question if you need to add details.

As for marking the question 'solved', please accept Eric's answer (the checkbox by the vote up/down) ins$$anonymous$$d of editing the title.

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.

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

7 People are following this question.

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

Related Questions

What variable type is this? 1 Answer

Camera rotation around player while following. 6 Answers

I want to rotate a object on double tap ,Can any One help me with this? 2 Answers

How to rotate an object around another 60 degrees with a keypress? 0 Answers

How do I rotate an object around another object with euler angles? 1 Answer


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