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 Scobbo · Jul 07, 2014 at 06:23 AM · rigidbodyforcetorque

Slow rigidbody movement in all directions but forward.

Hi, I have a short script that controls a spacecraft. I have two issues with it. Firstly the rotation doesn't change speed if I increase or decrease the MaxRotSpeed variable even though it is being calculated with it. Secondly I have no idea how I am going to slowly cease all movement in every direction other than the one I want to go in. At the moment if I turn while flying the velocity doesn't decrease as I move in a new direction except if move in the actively oppose it by flying in the exact opposite direction. At the moment all I am doing is adding speed in my new direction and keeping the speed in my old direction. Here is my full script: public class PlayerControlScript : MonoBehaviour {

     public float maxMovSpeed = 5.0f; // Maximum speed set by the engine component
     public float curMovSpeed = 0.0f; // Current speed set by the player increasing of decreasing the throttle
     public float accSpeed = 0.1f; // Speed at which the movSpeed can increase or decrease
     public float maxRotSpeed = 5.0f; // Maximum speed at which the craft can rotate
     public float brakePower = 0.97f;  // How quickly the brake affects the craft
 
     void FixedUpdate() {
         // Yaw, Pitch and roll
         float h = Input.GetAxis("Mouse X"); // Yaw
         float v = Input.GetAxis("Mouse Y"); // Pitch
         float roll = Input.GetAxis("Roll"); // Roll
 
         rigidbody.AddRelativeTorque(-v * maxRotSpeed, h * maxRotSpeed, roll * maxRotSpeed); // Use the 3 rotations in a vector that is multiplied by the max roll speed and added relatively to the rigidbody as torque
 
         // Accellerate
         // If the forward button is pressed add speed to move speed var
         if (Input.GetAxis("Forward") > 0.0f && curMovSpeed < maxMovSpeed) {
             curMovSpeed += accSpeed;
         }
         // Deccellerate
         // If the backward button is pressed remove speed from move speed var
         if (Input.GetAxis("Forward") < 0.0f && curMovSpeed > -maxMovSpeed){
             curMovSpeed -= accSpeed;
         }
 
         rigidbody.AddForce(transform.forward * curMovSpeed); // Add move speed var to rigidbody as force in forward direction
 
         // If the left or right buttons are pressed add lateral force accordingly
         if (Input.GetAxis ("Right") > 0.0f || Input.GetAxis ("Right") < 0.0f) {
             rigidbody.AddForce(transform.right * (curMovSpeed / 2) * Input.GetAxis ("Right"));
         }
 
         // If the brake button is pressed slow to a stop in all directions
         if (Input.GetAxis ("Brake") > 0.0f)
         {
             rigidbody.velocity = rigidbody.velocity * brakePower; 
         }
     }
 }
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.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Apply force and torque on different collider enter 0 Answers

Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers

Trying to apply a force on a ball at certain angles but the ball moves back and forth or otherwise moves erratically 1 Answer

Calculate force for torque by specifying a required velocity 1 Answer

Guided Missile 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