Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by S_Byrnes · Aug 19, 2015 at 08:36 AM · c#2drotationcontrol

2D C# Rotation Stopped Working Since Unity 5, Please Help?

Hello all, can anyone please tell me why my 2D rotation feature that I use on a sprite in my game has stopped working since I've updated to Unity 5?

Here is the code, I've removed all other elements that are used for movement up and down etc. I believe this is all that is needed to work out the problem.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControl : MonoBehaviour {
 
 float maxMove=2f; // speed of the movement of the object
 float maxTurn=50;   // max angle it turns up/down
 float maxGrav=500;
 float turnRate=10;
 
 Rigidbody2D rb2d;
 
     void Start() {
         
         rb2d = GetComponent<Rigidbody2D> ();
     }
 
     void Update() {
         float delta = 0;
         float deltaGrav = 0f;
 
         if (Input.GetKey (KeyCode.UpArrow)) {
             
             delta++;
 
         } else if (Input.GetKey (KeyCode.DownArrow)) {
 
             delta--;
 
         } else {
             deltaGrav--;
         }
 
         rb2d.rotation = Mathf.Lerp (rb2d.rotation, maxGrav * deltaGrav, turnRate * Time.deltaTime);
         
         rb2d.MovePosition (rb2d.position + Vector2.up * delta * maxMove * Time.deltaTime);
         
         rb2d.rotation = Mathf.Lerp (rb2d.rotation, maxTurn * delta, turnRate * Time.deltaTime);
 
     }
 }

Thank you all in advanced, I really appreciate the help!

Comment
Add comment · Show 6
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 maccabbe · Aug 19, 2015 at 11:16 AM 0
Share

Should grav/maxgrav should be controlling rb2d's rotation and not its position?

avatar image S_Byrnes · Aug 19, 2015 at 11:19 AM 0
Share

Possibly? I thought it was with the other two?

And it was working fine before I upgraded so I'm not sure..

avatar image S_Byrnes · Aug 21, 2015 at 04:17 AM 0
Share

Anyone have the solution? Even if it's a completely different one, I just need 2D rotations to work in this manner.

avatar image NoseKills · Aug 22, 2015 at 03:25 AM 0
Share

has stopped working

I just need 2D rotations to work

What do you mean ? What is happening and what do you want to happen ? Is the object not rotating at all ?

You have 2 separate lines adjusting rotation in each Update() call with all kinds of different values in $$anonymous$$athf.Lerp. $$anonymous$$aybe those 2 values are roughly complementary and neutralize each other's rotation ?

And your $$anonymous$$ovePosition adds the current position of the object on top of its old position every Update() which seems odd... It's really hard to figure out what you want to achieve.

avatar image S_Byrnes · Aug 22, 2015 at 04:07 AM 0
Share

Well I just need to object to rotate on the z axis, it's a 2D sprite, so imagine a head without a body that is looking up or down depending on which arrow key is being pressed.

Yeah, one of those lines is to accommodate for gravity (maxGrav) and the other is for rotation on key press.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

27 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Flip over an object (smooth transition) 3 Answers

BoxCollider2D rotates opposite mesh 1 Answer

Cinemachine camera rotating with player 2D 1 Answer

How do I flip a 3D object to look towards left or right on a 2D plane 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