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 /
This question was closed Dec 14, 2013 at 12:58 AM by robertbu for the following reason:

Other

avatar image
0
Question by Carbongrip · Dec 13, 2013 at 10:50 PM · c#rotationspeedspaceship

Rotation Speed

How can I set how fast a ship turns with rotation? say maybe degrees per sec or something? Heres the current code…

 using UnityEngine;
 using System.Collections;
 
 public class ShipControl : MonoBehaviour
 {
     public Transform ship;
     float flyingSpeed = 0;
     float turnSpeed = 50.0f;
     
     void Update ()
     {
         //Accelerate the ship using the thrust key.
         if(Input.GetKeyDown("e"))
         {
             if(flyingSpeed == 0)
             {
                 flyingSpeed = 2.5f;
             }
                 else if(flyingSpeed == 2.5f)
                 {
                     flyingSpeed = 5f;
                 }
                 else if(flyingSpeed == 5f)
                 {
                     flyingSpeed = 7.5f;
                 }
                 else if(flyingSpeed == 7.5f)
                 {
                     flyingSpeed = 10f;
                 }
         }
         
         //Decelerate the ship using the thrust button.
         if(Input.GetKeyDown("q"))
         {
             if(flyingSpeed == 10f)
             {
                 flyingSpeed = 7.5f;
             }
                 else if(flyingSpeed == 7.5f)
                 {
                     flyingSpeed = 5f;
                 }
                 else if(flyingSpeed == 5f)
                 {
                     flyingSpeed = 2.5f;
                 }
                 else if(flyingSpeed == 2.5f)
                 {
                     flyingSpeed = 0;
                 }
                     else
                     {
                         flyingSpeed = 0;
                     }
         }
         
         if(Input.GetKey("w"))
         {
             ship.transform.Rotate(20.0f * Time.deltaTime, 0.0f, 0.0f);
         }
         
         if(Input.GetKey("s"))
         {
             ship.transform.Rotate(-20.0f * Time.deltaTime, 0.0f, 0.0f);
         }
         
         if(Input.GetKey("d"))
         {
               ship.transform.Rotate(0.0f, turnSpeed * Time.deltaTime, 0.0f * Time.deltaTime, Space.World); //and then turn the plane
            }
         
         if(Input.GetKey("a"))
         {
               ship.transform.Rotate(0.0f, -turnSpeed * Time.deltaTime, 0.0f * Time.deltaTime, Space.World); //and then turn the plane
            }
         
         ship.transform.Translate(0,-flyingSpeed * Time.deltaTime,0);//move the ship
     }
 }
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 robertbu · Dec 13, 2013 at 11:03 PM 0
Share

Not sure what you are asking. 'turnSpeed * Time.deltaTime' in your Rotate is degrees per second. If you are looking for a total for all axes, create a Vector3 containing all three turns and look at the magnitude of the vector3. Note since 'turnSpeed' is public, the value must be set in the inspector after the script is added.

avatar image Carbongrip · Dec 13, 2013 at 11:16 PM 0
Share

it says lol "How can I set how fast a ship turns" meaning making a set turn speed...

avatar image robertbu · Dec 13, 2013 at 11:26 PM 0
Share

Again, it is unclear what you are asking. Your code uses 'turnSpeed', and, because you use 'deltaTime', your calculation are already in degrees per second. To make a change, select your game object with the above script in the Hierarchy view, and in the inspector change the value of 'turnSpeed'.

avatar image Carbongrip · Dec 13, 2013 at 11:48 PM 0
Share

I have turn speed but don't under stand what value it holds...

avatar image insominx · Dec 13, 2013 at 11:52 PM 1
Share

The Rotate function takes in an angle (Euler). If you apply that over time you get degrees per second. Ex: turnspeed = 10 so turnspeed * Time.delta time will add up to 10 over the course of 1 second.

Show more comments

1 Reply

  • Sort: 
avatar image
0

Answer by insominx · Dec 13, 2013 at 11:17 PM

Here's an example:

 public class SpinningBox : MonoBehaviour {
 
     public float yawDegreesPerSecond = 10.0f;
 
     // Update is called once per frame
     void Update () {
         Vector3 localEulers = transform.localEulerAngles;
         localEulers.y += yawDegreesPerSecond * Time.deltaTime;
         transform.localEulerAngles = localEulers;
     }
 }
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

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Images Rotation 1 Answer

Space Torpedo 1 Answer

C# - How to vary rotation speed according to movement speed 1 Answer

Distribute terrain in zones 3 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