Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Oyunja · May 14, 2020 at 02:08 PM · rotatingspeed up

How to increase and decrease rotating speed

I have speed data like 10 m/s, 6 m/s, 15 m/s, 20 m/s. I want to rotating speed increase by 10 m/s after time speed 6 m/s something like that variable speed. I already wrote rotating speed script code as follow:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class RotateGO : MonoBehaviour { float speed = 1.0f;

 // Start is called before the first frame update
 void Start()
 {
     
 }

 // Update is called once per frame
 void Update()
 {
     //transform.Rotate(Vector3.up * speed * Time.deltaTime);
     transform.Rotate(speed, 0, 0);
     speed += Time.deltaTime;
     speed -= 0.4f;
            }

}

Please help for write correct script file Thank you

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
1
Best Answer

Answer by Dizy · May 14, 2020 at 02:37 PM

Hi, there is no such m/s things about rotation but only degrees. If i understand you want to increase your rotation based on the elapsed time.

That should do the trick :

 public float Speed;
 private float _currentTime;
 
 void Update() {
    _currentTime += Time.deltaTime;
    transform.Rotate(Speed * _currentTime, 0, 0)
 }

You can also use rigidBody.AddTorque() if you want to simulate this using physics.


EDIT : to calculate your speed based on your time

For that you need to use a cross product with backing zero.

With MinTime, MaxTime, MinSpeed, MaxSpeed, _currentTime, _currentSpeed

 _currentSpeed = MinSpeed + ((MaxTime - MinTime) * (_currentTime - MinTime) / (MaxSpeed - MinSpeed))

Not tested but it's seems to be okay.

You probably need to add some condition to check if the _currentTime is below MinTime

Comment
Add comment · Show 2 · 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 Oyunja · May 15, 2020 at 07:12 AM 0
Share

Yes I tried it. Object continuously rotated. I need range of time and speed. $$anonymous$$y mean how to write code for time of range (1-60) and speed of range (11-25). For example: Time 1 at speed 11 Time 2 at speed 15 ` Time 3 at speed 20 Please help me to write code

avatar image Oyunja · May 15, 2020 at 12:42 PM 0
Share

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class RotateGO : $$anonymous$$onoBehaviour {

 public int speed;
 public int time;

 void Start()
 {
    
   
 }

 void Update()
 {
     transform.Rotate(+speed * Time.deltaTime, 0, 0);
     time = Random.Range(1, 5000);
     speed = Random.Range(5, 25);
     Debug.Log("time: " +time+",speed:"+speed);

     if (time == 10)
     {
         transform.Rotate(speed * Time.deltaTime, 0, 0);
         print("1000");
     }
     else
     {
         if (time == 1000)
         {
             transform.Rotate(speed + 10 * Time.deltaTime, 0, 0);
             print("2000");
         }
         else
         {
             if (time == 3000)
             {
                 transform.Rotate(speed + 20 * Time.deltaTime, 0, 0);
                 print("3000");
             }
          }

       }

  }

}

avatar image
0

Answer by Oyunja · May 15, 2020 at 12:44 PM

This is my code. It's running well. But I want to change "time Random.Range" by the Time Loop. How to write and fix Time loop code in this script?

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 Dizy · May 15, 2020 at 12:55 PM 0
Share

https://docs.unity3d.com/ScriptReference/Time.html

realtimeSinceStartup The real time in seconds since the game started (Read Only).

Use the Unity documentation, RTF$$anonymous$$ if i can say.

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

200 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

How i apply rotating animation via script ? 0 Answers

How to speed up player character in ENDLESS RUNNER after colliding with powerup?? 0 Answers

Rotating a grid, 0 Answers

accelerate speed 0 Answers

Is there a OnRotation Event for gameObject? 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