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 qetinac · Mar 21, 2017 at 01:55 AM · unity 5rotationcuberotation axis

simple 360 degree Cube-rotation around y axis

Hi guys,

My Problem - i want to implement simple 360d. Cube -Rotation around Y-axis when i press the spacebar (so this Cube rotates itself only once when i press the spacebar and then stops) . How can i do this?

Heres my current code:

 void Start () {
 
         mSpeed = 3f;
         RB = GetComponent<Rigidbody>();
 
     }
 
     // Update is called once per frame
     void Update () {
         transform.Translate(mSpeed*Input.GetAxis("Horizontal")*Time.deltaTime,0f,mSpeed*Input.GetAxis("Vertical")*Time.deltaTime);
         //transform.Rotate(Vector3.up, 100 * Time.deltaTime);
 
         if (Input.GetButtonDown ("Jump")) 
         {
             RB.velocity = new Vector3 (0,5,0);
         }
 
     }
Comment
Add comment · Show 1
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 qetinac · Mar 20, 2017 at 08:08 PM 0
Share

i want to see one simple 360 rotation of my cube around y axis

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by doVa09 · Mar 22, 2017 at 01:08 AM

Just do this:

 void Update()
 {
  if (Input.GetButtonDown ("Jump")) 
        transform.Rotate(Vector3.up * mSpeed * Time.deltaTime);
 }

And if you want it to rotate while Space is pressed and stops when Space is released then just make

   if (Input.GetButton("Jump"))   
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 Bunny83 · Mar 22, 2017 at 01:45 AM 0
Share

It makes no sense to use deltaTime in an "xxxDown" event. It's a one time event and nothing continuous. If you use GetButton it of course is required.

avatar image
0

Answer by Spidlee · Mar 22, 2017 at 03:06 AM

Very roughly, maybe this can help you:

 bool isRotAnimPlaying = false;
 float mSpeed = 3f;
 float currRot = 0f;
 const float rotMax = 360f;
 ...
 void Update ()
 {
     // toggle rot anim state
     if(Input.GetButtonDown("Jump"))
     {
         isRotAnimPlaying = !isRotAnimPlaying; 
         // reset rot tracker to allow for new rot animation
         currRot = 0f; 
     }
         
     // play animation
     if(isRotAnimPlaying)
     {
         float step = mSpeed * Time.deltaTime;  
         // rotate object
         transform.Rotate(Vector3.up * step);         
         // increment amount of rotation done
         currRot += step;
         
         // reached rot destination, stop animation
         if(currRot >= rotMax)
         {
             isRotAnimPlaying = false; 
             // reset rot tracker to allow for new rot animation
             currRot = 0f; 
         }
     }
 }
 

It's not precise in terms of 100% stop at 360 degrees, but it should get the desired effect you want.

Comment
Add comment · 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

6 People are following this question.

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

Related Questions

How to Rotate Plane of Cube Around its Center? (Rotate Vectors Around Point/Axis/Direction) 1 Answer

Rotate object of certain degree on button press 1 Answer

Build rotation tool for level editor 0 Answers

CAR ROTATING HELP 2 Answers

How to find or compute or look for overall/max RPM by simply checking for rotation? 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