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 jarratt51 · Mar 25, 2019 at 03:07 PM · scripting problemphysicsspacetorque

Kill Rotation of object using forces

Hi, I'm making a simple space flight simulator as a base for future games. The Player spaceship has realistic intertia based physics for space using Torque to induce turns in any axis similar to how RCS works in Kerbal Space Program. I want to create a void which (when a button is pressed) kills the rotation using the control torques similar to SAS in Kerbal Space Program but don't know how. Hard to explain really I'll attach my ShipController code.

Thanks :)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ShipController : MonoBehaviour
 {
     //Input Controls
     private float m_Tilt;
     private float m_Pitch;
     private float m_Yaw;
     private float m_MoveHorizontal;
     private float m_MoveVertical;
     private float m_MoveForBack;
     private float m_Throttle;
     private float m_ReverseEngineDirection;
     //RCS Roll Pitch Yaw multiplyers
     public float RollMultiplyer = 1;
     public float PitchMultiplyer = 1;
     public float YawMultiplyer = 1;
     //RCS Thrust Size 
     public float ThrustMove = 1000;
     public float ThrustRotate = 100;
     //Main Engine Parameters
     public float MainEngineThrust = 10000;
     private List<int> MainEngineThrustList = new List<int>();
     public int ThrottleSelect;
     //parent rigidbody
     public Rigidbody Ship;
     //UIText
     public Text T_Throttletext;
     public Text T_Velocity;
 
 
 
 
     public void SelectShip()
     {
         Ship = GetComponent<Rigidbody>();
 
     }
 
     private void InputControls()
     {
         m_Yaw = Input.GetAxis("Horizontal");
         m_Pitch = Input.GetAxis("Vertical");
         m_Tilt = Input.GetAxis("Tilt");
         m_MoveHorizontal = Input.GetAxis("MoveHorizontal");
         m_MoveVertical = Input.GetAxis("MoveVertical");
         m_MoveForBack = Input.GetAxis("MoveForBack");
         m_Throttle = Input.GetAxis("ThrottleControl");
         m_ReverseEngineDirection = Input.GetAxis("ReverseEngineDirection");
     }
 
     private void MainEngineThrustSize()
     {
         for(int i = 0; i <= 100; i++)
         {
             MainEngineThrustList.Add(i);
         }
         
     }
 
     public void MainEngine()
     {
         InputControls();
         MainEngineThrustSize();
 
        
 
         if (Input.GetKey("]"))
         {
             if(ThrottleSelect == 100)
             {
                 ThrottleSelect = MainEngineThrustList[ThrottleSelect];
             }
             else
             {
                 ThrottleSelect = MainEngineThrustList[ThrottleSelect + 1];
             }
             Debug.Log(ThrottleSelect);
         }
         else if (Input.GetKey("["))
         {
             
            if(ThrottleSelect == 0)
             {
                 ThrottleSelect = MainEngineThrustList[ThrottleSelect];
             }
             else
             {
                 ThrottleSelect = MainEngineThrustList[ThrottleSelect - 1];
             }
             Debug.Log(ThrottleSelect);
         }
 
         Ship.AddForce(transform.forward * ThrottleSelect * MainEngineThrust);
 
     }
 
     private void RCSMove()
     {
         InputControls();
         SelectShip();
 
         //Vertical Movement
         Ship.AddForce(transform.up * m_MoveVertical * ThrustMove);
         //ForwardBackMovement
         Ship.AddForce(transform.forward * m_MoveForBack * ThrustMove);
         //LeftRightMovement
         Ship.AddForce(transform.right * m_MoveHorizontal * ThrustMove);
 
     }
 
 
     private void RCSRotate2()
     {
         InputControls();
         SelectShip();
 
         //Roll
         Ship.AddRelativeTorque(Vector3.forward * RollMultiplyer * -m_Tilt);
         //Pitch
         Ship.AddRelativeTorque(Vector3.right * PitchMultiplyer * m_Pitch);
         //Yaw
         Ship.AddRelativeTorque(Vector3.up * YawMultiplyer * m_Yaw);
 
     }
 
     public void UIData()
     {
         T_Throttletext = GetComponent<Text>();
         T_Velocity = GetComponent<Text>();
     }
 
     private void UIupdate()
     {
         MainEngine();
         SelectShip();
 
 
         T_Throttletext.text = "Throttle:" + ThrottleSelect.ToString();
         T_Velocity.text = "Velocity:" + Ship.velocity.magnitude.ToString("f0");
     }
 
     // Update is called once per frame
     private void Start()
     {
 
         MainEngineThrustSize();
         ThrottleSelect = MainEngineThrustList[0];
 
     }
 
 
 
     void FixedUpdate()
     {
         MainEngine();
         RCSMove();
         RCSRotate2();
         UIupdate();
     }
 
 }
 
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 xxmariofer · Mar 25, 2019 at 04:16 PM 0
Share

well, if you are using unity physics engine, yoou could use the angular drag in the rigidbody, try increasing it and check if that fixed a bit the problem

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.

Follow this Question

Answers Answers and Comments

230 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 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 do I completely turn off/avoid using the physics engine? 2 Answers

using a button to stop running script 1 Answer

Missiles attached with FixedJoint cause too much torque for airplane physics 1 Answer

trouble making a fast projectile 2 Answers

Why are these object passing through each other? 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