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 /
  • Help Room /
avatar image
0
Question by faizanmir009 · May 20, 2020 at 08:16 PM · rigidbodyvelocityforcetorque

Torque applies to one wheel, but inconsistently to the other wheel

I have a GameScript class which is derived by another class WheelScript; it is meant to apply torque to a rigidbody in different directions depending upon the key pressed.

However the result to this is that one of the rigidbodies rotates fine but the other one doesn't (say the right wheel rotates but the left doesn't turn or even if it does, it doesn't move with the same angular velocity as the first one)

Base Class is as

 public class GameScript : MonoBehaviour
 {
     public static GameScript instance;
     protected float Force;
 
     protected virtual void  Print(GameObject gameObject) {
         print(gameObject.name);
     }    
 
     protected virtual void MoveForward(Rigidbody rigidBody, int identifier) {
         if(identifier == 1)
         {
             rigidBody.AddRelativeTorque(-Vector3.forward * Force); 
         }
         else
         {
             rigidBody.AddRelativeForce(-Vector3.forward * Force);
         }
     }
 
     protected virtual void MoveLeft(Rigidbody rigidBody, int identifier) {
         if (identifier == 1)
         {
             rigidBody.AddRelativeTorque(-Vector3.forward * Force);
         }
         else
         {
             rigidBody.AddRelativeForce(-Vector3.forward * Force);
         }    
     }
 
     protected virtual void MoveRight(Rigidbody rigidBody, int identifier) {
         if (identifier == 1)
         {
             rigidBody.AddRelativeTorque(Vector3.forward * Force);
         }
         else
         {
             rigidBody.AddRelativeForce(-Vector3.forward * Force);
         }    
     }
 
     protected virtual void MoveBack(Rigidbody rigidBody, int identifier) {
         if (identifier == 1)
         {
             rigidBody.AddRelativeTorque(-Vector3.forward * Force);
         }
         else
         {
             rigidBody.AddRelativeForce(-Vector3.forward * Force);
         }
     }
 }

Child Class is as :

 public class WheelScript : GameScript
 { 
     [SerializeField] private int identifier;
     Rigidbody body;
     [SerializeField] float force;
 
     private void Start()
     {
          body = GetComponent<Rigidbody>();
          Force = force;
     }
 
     void Update()
     {
         if (Input.GetKey(KeyCode.W))
         {
             MoveForward(body, identifier);
         }
         else if (Input.GetKey(KeyCode.A))
         {
             MoveLeft(body, identifier);
         }
         else if (Input.GetKey(KeyCode.D))
         {
             MoveRight(body, identifier);
         }
         else if (Input.GetKey(KeyCode.S))
         {
             MoveBack(body, identifier);
         }
     }
 }


The Hinges are attached as shown in the picturealt text:

Hinges point in opposite direction as (0,0,1) and (0,0,-1) (Axis of the hinge with anchor at (0,0,0) which is the pivot of the T-shaped body

for further reference please read this link text

upload-4.png (287.5 kB)
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

249 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 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

Figuring out what the acceleration will be before applying force to RigidBody2D 0 Answers

Falling Platform 1 Answer

Custom touch control stops abruptly! 0 Answers

Question about having a Rigidbody follow another GameObject via forces. 1 Answer

Instant rotation bug when rotating clockwise 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