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
7
Question by anosmicAnimator · Nov 21, 2013 at 02:05 AM · 2drotationsprite

Trying to rotate a 2D sprite

I've got this code attached to a 2D sprite that I want to rotate. So far I'm working on making it rotate left when the left arrow key is pressed. I get no parsing errors, but when I run the game, the code doesn't work. Any idea what I'm doing wrong?

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetButtonDown ("left"))
             RotateLeft();
     }
 
     void RotateLeft () {
         Quaternion theRotation = transform.localRotation;
         theRotation.z *= 270;
         transform.localRotation = theRotation;
     }
 }
 
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

2 Replies

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

Answer by Eric5h5 · Nov 21, 2013 at 03:50 AM

 void RotateLeft () {
    transform.Rotate (Vector3.forward * -90);
 }
Comment
Add comment · Show 9 · 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 anosmicAnimator · Nov 21, 2013 at 04:04 AM 0
Share

Looks like I have another problem now...

 UnityException: Input Button left is not setup.
  To change the input settings use: Edit -> Project Settings -> Input
avatar image prof · Nov 21, 2013 at 04:29 AM 0
Share

Input

avatar image Eric5h5 · Nov 21, 2013 at 04:31 AM 1
Share

Did you do what the error message says?

avatar image anosmicAnimator · Nov 21, 2013 at 04:38 AM 0
Share

Alright, it works now. Thanks for your help, everybody!

avatar image aman_jha · Oct 13, 2014 at 02:37 PM 2
Share

$$anonymous$$ark this answer as correct, then.

Show more comments
avatar image
2

Answer by epicpython · Sep 18, 2016 at 02:41 PM

Instead of subtracting 90 from the forward direction, you can use Vector3.forward and vector3.back:

 //rotate counterclockwise
 transform.Rotate (Vector3.forward);
 
 //rotate clockwise
 transform.Rotate (Vector3.back);

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 WarriorGecko · Oct 30, 2020 at 10:21 AM 0
Share

Where do I put this 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

28 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

Related Questions

2D Sprite Animation - Rotate animation on axis 1 Answer

Ground checking with a frequently rotating player 2 Answers

2D LookAt not working as intended 1 Answer

2 fingers sprite rotation 1 Answer

Simulate character torso rotation in 2d game 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