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 HEATH3N · Aug 07, 2014 at 09:51 AM · 2drotationtransformvector3translate

Simultaneously translating and rotating 2D sprite?

I have a 2D object (a PNG file I dragged onto the screen) which is a circle I would like to move left and right when the correct side of the screen is touched and have it rotate in the respective direction while doing so. Naturally, I thought using transform.Translate and transform.Rotate would be the proper way to do this, as such:

 void Update() {

     if (Input.touchCount > 0)
     {
         var touch = Input.GetTouch (0);
         if (touch.position.x < Screen.width/2)
         {
             transform.Translate (Vector3.left * Time.deltaTime);
                             transform.Rotate (Vector3.forward * Time.deltaTime);

         }
         else if (touch.position.x > Screen.width/2)
         {
             transform.Translate (Vector3.right * Time.deltaTime);
                             transform.Rotate (Vector3.back * Time.deltaTime);
         }
     }
 }

For whatever reason, rotating left and right didn't work so I tried forward and back which at least rotated it. The problem is that the circle moves in an arc, I'm assuming because as it rotates, the direction of "right" changes. Also, the circle gets squashed into an ellipse after a bit, assumedly because I'm rotating on the wrong axis. I've literally just started using Unity yesterday; what is the most concise and best way to accomplish what I'd like?

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

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

Answer by HEATH3N · Aug 07, 2014 at 11:17 PM

Found the solution courtesy of a user on the GameDev Stack Exchange. The following code works perfectly to achieve what I'd like:

 float degreesPerSecond = 45;
 if (touch.position.x < Screen.width/2)
 {
     transform.Translate (Vector3.left * Time.deltaTime, Space.World);
     transform.Rotate (Vector3.forward, degreesPerSecond * Time.deltaTime);
 }
 else if (touch.position.x > Screen.width/2)
 {
     transform.Translate (Vector3.right * Time.deltaTime, Space.World);
     transform.Rotate (Vector3.back, degreesPerSecond * 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to rotate a child where its parent has another Z rotation? | Issue when rotating towards the mouse after it goes on the other side of the player 0 Answers

Move child objects in the opposite direction of parent object 0 Answers

Moving by rotation of objects 0 Answers

Why do grouped Terrain objects move together but don't rotate as one? 1 Answer

Connecting transform with Vector3 4 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