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
0
Question by Lizard · Dec 06, 2013 at 05:43 PM · c#cube

Cube rotation and force

Hi guys. I'm trying to create a game similiar to "Ahtung! Die Kurve". I'm trying to get those cubes to rotate with "a" and "d" buttons but it happends very slow. Please help me to get rid of that problem.

Here is my code for movement:

 void Update()
     {
         if (networkView.isMine)
         {
             InputMovement();
             InputColorChange();
         }
         else
         {
             SyncedMovement();
         }
         
     //===Force===========================
         
     transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);    
         
     
     }

     //===Movement========================================
     public void InputMovement()
     {
         
         
         /*if(Input.GetKey(KeyCode.DownArrow))
             transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
         
         if(Input.GetKey(KeyCode.LeftArrow))
             transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
         
         if(Input.GetKey(KeyCode.RightArrow))
             transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
         
         */
          if(Input.GetKey(KeyCode.W)) 
        transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
  
        if(Input.GetKey(KeyCode.S)) 
        transform.Translate( -1 * Vector3.forward * Time.deltaTime * moveSpeed);
  
        if(Input.GetKey(KeyCode.A)) 
        transform.Rotate(0,-1,0); 
  
        if(Input.GetKey(KeyCode.D)) 
        transform.Rotate(0,1,0); 
         
     }
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
0
Best Answer

Answer by robertbu · Dec 06, 2013 at 05:46 PM

Your code for 'A' and 'D' rotation should just like the you have comment out for LeftArrow and RightArrow. Replace lines 41 - 45 with:

 if(Input.GetKey(KeyCode.A))
     transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
  
 if(Input.GetKey(KeyCode.D)
     transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);

The 'turnSpeed' variable controls the speed of the turn. If 'turnSpeed' is a public variable, then you must make the change in the Inspector. Changing the value in the script will not change the value used by the component. If you've copied and pasted this code, you will need to declare a 'turnSpeed' variable and give it an initial value.

Note you can also use something similar to the code you already have:

    if(Input.GetKey(KeyCode.D)) 
        transform.Rotate(0,turnSpeed * Time.deltaTime,0); 
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 Lizard · Dec 06, 2013 at 06:01 PM 0
Share

Ok i changed value in inspector. Can you tell me what assigning a value in script doesn't work?

avatar image robertbu · Dec 06, 2013 at 06:06 PM 0
Share

When a variable is 'public', then it is visible in the inspector. So if I have:

 public int someVariable = 23;

'someVariable' only gets set to 23, at the time the script is attached to the game object. After that, it takes its value from the Inspector. If you go to the game object with your script, you will see a gear icon in the upper right corner. You can click on the gear and select 'reset' if you want all the public variables to be reset to their default values. So if you change public values in the script and want to propagate those values to the Inspector, you can select 'reset'. As an alternative, if you plan on making the changes in the script, just make the variables 'private'.

avatar image
0

Answer by Lizard · Dec 06, 2013 at 06:16 PM

Thank You ;)

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Dynamic Cube Physics like other games 0 Answers

C# sticking to Cube corners position (raycasting AI script) 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