• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by 825orion · Jul 28, 2016 at 07:41 PM · physicsflight sim

Rotate Slightly With Torque

Hello,

I am working on a pretty basic flight simulator, using a helicopter model taken from the asset store. I wrote a basic movement script for it. It will move the helicopter using AddForce along all axis, but remaining in the same direction. My question is how to use torque to rotate the helicopter slightly, to make it look more realistic. My current code is as follows:

 using UnityEngine;
 using System.Collections;
 
 public class HeloFlight : MonoBehaviour {
 
     private Rigidbody rigidbody;
 
     // Use this for initialization
     void Start () {
         rigidbody = GetComponent<Rigidbody> ();
     }
     public int vertspeed = 0;
     public int horspeed = 0;
     public int lrspeed = 0;
     public int torque;
     public bool lightstate = false;
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKey(KeyCode.Q))
             vertspeed++;
             Debug.Log("Increasing Vertical Speed");    
             //Enact Movement
 
         if (Input.GetKey(KeyCode.E))
             vertspeed--;
             Debug.Log("Decreasing Vertical Speed");
             //Enact Movement
 
         if (Input.GetKey (KeyCode.W))
             horspeed++;
             Debug.Log ("Increasing Horizontal Speed");
             //Enact Movement
 
         if (Input.GetKey (KeyCode.S))
             horspeed--;
             Debug.Log ("Increasing Horizontal Speed");
             //Enact Movement
 
         if (Input.GetKey (KeyCode.A))
             lrspeed--;
             Debug.Log ("Increasing Right Speed");
             //Enact Movement
 
         if (Input.GetKey (KeyCode.D))
             lrspeed++;
             Debug.Log ("Increasing Left Speed");
             //Enact Movement
 
         if (Input.GetKey (KeyCode.X))
             rigidbody.useGravity = true;
             
         if (Input.GetKey (KeyCode.Y))
             rigidbody.useGravity = false;
                 
 
 
 
         if (!Input.GetKey (KeyCode.D) && !Input.GetKey (KeyCode.A)) {lrspeed = 0;}
 
         if (!Input.GetKey (KeyCode.Q) && !Input.GetKey (KeyCode.E)) {vertspeed = 0;}
 
         if (!Input.GetKey (KeyCode.W) && !Input.GetKey (KeyCode.S)) {horspeed = 0;}    
     
 
         rigidbody.AddForce (lrspeed * Vector3.right);
         rigidbody.AddTorque (torque * Vector3.right);
         rigidbody.AddTorque (torque * Vector3.left);
         rigidbody.AddForce (horspeed * Vector3.forward);
         rigidbody.AddTorque (torque * Vector3.forward);
         rigidbody.AddTorque (torque * Vector3.back);
         rigidbody.AddForce (vertspeed * Vector3.up);
         rigidbody.AddTorque (torque * Vector3.up);
         rigidbody.AddTorque (torque * Vector3.down);
 
     }
 }


As you can see I have rigidbody.AddTorque but it does absolutely nothing. Ideas? Thanks in advance.

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why do my physics objects rotate randomly sometimes when reparented 1 Answer

Is it possible to put collision detection in an if statement? 0 Answers

Detect when near edge of an object (3D) 0 Answers

Using AddForce with a more specific rotation 2 Answers

Noob Question | Friction and Weight 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