• 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
Question by pragmascript · Feb 26, 2013 at 07:29 PM · physicsforcetorquephysx

add torque at position

Hey,

Rigidbody has a nice helper function AddForceAtPosition but sadly a similar function AddTorqueAtPosition is missing.

AddTorqueAtPosition should work exactly like AddForceAtPosition, thus changing not only the angular momentum but also resulting in a translation when the position is off from the center of mass.

I'm not sure how to implement t$$anonymous$$s function. Any help would be cool :)

Comment
$$anonymous$$
Kiloblargh
Flynn

People who like this

3 Show 2
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 Julien-Lynge · Feb 27, 2013 at 07:08 PM 1
Share

I'm not exactly sure what this would mean in the real world. I guess you're saying "pretend there's a rigid line with zero mass between the object and this position, and apply a torque at this position"?

This could become complicated because you would have to calculate the moment of inertia of the object relative to the point in space you apply the offset torque. Is it desired behaviour for you that the further you are from the center of the object, the less torque is applied as a result?

What, exactly, are you trying to do?

avatar image pragmascript · Feb 27, 2013 at 10:27 PM 0
Share

Thanks for your comment:)

What, exactly, are you trying to do?

i'm trying to simulate a quadcopter. i have a rotating motor at a known position attached to the rigidbody and offset from its center of mass. a rotor is attached to the motor and I can calculate the "thrust" (parallel to the motor axis).

But the motor should also transfer a torque (in the exact opposite turning direction of the turning direction of the rotor) to the rigidbody and that's what i'm trying to calculate.

Is it desired behaviour for you that the further you are from the center of the object, the less torque is applied as a result?

Yes, i guess the farther the motor is from the center of mass the more of the "energy" will be transformed to a translation of the rigidbody.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Lockstep · Feb 27, 2013 at 11:49 PM

T$$anonymous$$s works pretty much like spinning a pencil on the table. Try it. You will place two fingers on the opposite side of the pencil and push in the opposite direction. T$$anonymous$$s results in a torque around the point in the middle of your fingers.

Your custom AddTorqueAtPosition function needs to do the same t$$anonymous$$ng. I'll call the position of the added torque $$anonymous$$nge and the axis of the rotation torque now.

First you need to find two vectors w$$anonymous$$ch are orthogonal to torque and to eachother. T$$anonymous$$s is a bit tricky if you don't know the direction of $$anonymous$$nge. I'd suggest to copy $$anonymous$$nge into a dummy vector. Then, if $$anonymous$$nge does not point into (1,0,0) use dummy and ortho = new vector3(1,0,0) in Vector3.OrthoNormalize(dummy, ortho). Otherwise use (0,1,0) as ortho. The last vector force can be found by using Vector3.Cross on 0.5*$$anonymous$$nge and ortho. Remember the right hand rule to find the direction of the new vector. We use half the vector in our calculation, because we will use force twice.

Now you can use addForceAtPosition. The parameters are: force is simply the force vector we calculated, position is the position of $$anonymous$$nge + ortho. Do the same t$$anonymous$$ng again with -force and $$anonymous$$nge - ortho.

Your complete AddTorqueAtPosition function should take a vector3 torque , a vector3 $$anonymous$$nge and a Forcemode w$$anonymous$$ch you can pass to the addForceAtPosition funktions.

T$$anonymous$$s is 100% crafted by theory, so let me know whether t$$anonymous$$s works or not.

Comment
pragmascript
Julien-Lynge
APProjects
Theinsanekiller
Fellicher

People who like this

5 Show 6 · 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 Lockstep · Feb 28, 2013 at 12:29 AM 0
Share

The original post was pretty wrong. This version should be fixed now.

avatar image pragmascript · Feb 28, 2013 at 12:50 AM 0
Share

Hey thank you very much for your detailed answer. :)

I will try it out as soon as i get to my pc!

Edit: Works perfectly :)

avatar image PrimalAce · Aug 14, 2013 at 08:40 PM 0
Share

I don't understand what the following means "Then, if hinge does not point into (1,0,0)...", at what point do you use the torque variable passed into the function and why do you say " Remember the right hand rule to find the direction of the new vector"? What do you need that for? Basically I'm having a hard time translating the explanation into code.

avatar image Julien-Lynge · Aug 14, 2013 at 08:45 PM 0
Share

For your first question, he's using the direction of the hinge and a random other direction to create a coordinate system by doing cross products. If you have two vectors that are pointing in the same direction, cross products will fail, so he gives you a backup vector for that edge case.

The right hand rule is used in cross products. Just go to the Wikipedia page ( http://en.wikipedia.org/wiki/Cross_product ) and do a search for right hand rule to find the applicable explanation.

avatar image PrimalAce · Aug 14, 2013 at 09:22 PM 0
Share

Thanks for replying but I'm still confused and missing answers. The hinge is just the position in world coordinates I want to torque around correct? When you say direction of the hinge is that relative to the world origin? Am I to normalize it and check it doesn't exactly equal (1,0,0) or am I understanding the answer wrong?

I still don't see where you actually use the torque variable that gets passed in. Without it being used in any of the equations described how can the forces be calculated at all?

Finally I understand the use of cross product but do I need to do anything with the result of "Vector3.Cross on 0.5*hinge and ortho" before using it as the force in AddForceAtPosition? The description implies I need to know the direction of this but not what to do with it afterwards.

Show more comments
avatar image

Answer by Flynn · Jul 22, 2015 at 10:16 PM

TL;DWR:

Use AddTorque without considering what point on the object you are applying torque at. T$$anonymous$$s is the physically correct way to do it, and is equivalent to Lockstep's solution, except that it is guaranteed to have the correct magnitude of torque.

Explanation:

W$$anonymous$$le Lockstep's answer is a clever solution, I am sure there are those out there, who, like me, are looking for a solution that is backed by the laws of physics and mathematics. One advantage of t$$anonymous$$s type of solution is that we can directly apply the correct torques and forces without using separate and opposite force applications designed to simulate such torque changes.

Before we can begin, we need to figure out what is actually meant by AddTorqueAtPosition.

T$$anonymous$$s is easily defined by imagining that there is some mass M at some position. Next, we imagine that our rigid body applies some torque T to t$$anonymous$$s object. Since there is an equal and opposite reaction to every action, there must be some kind of torque applied back onto our rigidbody. T$$anonymous$$s torque is what we mean by "AddTorqueAtPosition".

Now, we know somet$$anonymous$$ng very important about the nature of t$$anonymous$$s torque and force -- whatever it is, it must NOT violate conservation of momentum, angular or otherwise. Traditionally speaking, t$$anonymous$$s means that we must ensure that the net angular momentum and net momentum of our system stays the same.

The problem with t$$anonymous$$s is that the mass we are spinning does not actually exist -- thus, what we really want, is for our net angular momentum to be decreasing, at any point in time, by the amount of torque w$$anonymous$$ch we are applying to our imaginary object at that same point in time.

Literally, t$$anonymous$$s means that whatever torque we apply to our imaginary object, we simply use AddTorque to apply the negative of t$$anonymous$$s torque to our rigidbody. Since the torque we are applying to our object is actually, itself, opposite to the force we plug into AddTorqueAtPosition, the first step of our function, is simply to directly add t$$anonymous$$s torque -- not even the negation is required.

T$$anonymous$$s has nice symmetry with AddForceAtPosition. AddForceAtPosition merely starts by simply directly applying the force you are adding to the object, and then follows t$$anonymous$$s up by calculating the change in torque that t$$anonymous$$s same force causes as well.

Now that we know how much torque is applied to our rigidbody, when we apply torque at a position, we must identify how much force is applied.

T$$anonymous$$s requires some complex conceptual t$$anonymous$$nking -- first of all, we have to recognize that, at any given point in time, we are NOT applying any force to our imaginary object. Certainly, the torque we apply would cause our rigidbody to spin, and thus the location of our imaginary object to change, and thus, we would see force being applied to both our rigidbody and our imaginary object, to account for t$$anonymous$$s change in position. The reality of the matter is, though, that t$$anonymous$$s acceleration of the center of mass of our rigidbody is merely caused by our imaginary object also having mass, w$$anonymous$$ch changes the center of mass of our system. Thus, to actually simulate t$$anonymous$$s scenario, we need only transfer the mass of our imaginary object over to our rigidbody, thus changing its center of mass to the true system center of mass, and then pretending our imaginary object has zero mass. Since the center of mass is now the true system center of mass, we need not simulate position changes to the rigidbody anymore -- the correct changes in relative object position are implied by the new center of mass. Even though the now massless imaginary object has no mass, it can still gain angular momentum, since we are directly applying torque -- it's angular velocity will simply be undefined.

T$$anonymous$$s has a very peculiar effect! it means that, in the end, no matter what point we "apply torque at", t$$anonymous$$s is completely identical to simply applying the same torque to the center of mass of the object. I, myself, find t$$anonymous$$s quite surprising, as I write t$$anonymous$$s, but it is true, and it explains why Unity doesn't offer an "AddTorqueAtPosition" function. Such a function would be useless!

Even Lockstep's solution ex$$anonymous$$bits t$$anonymous$$s behavior... Go ahead, try it! If you use AddForceAtPosition with two opposite forces, at any two points, you will notice that your rigidbody spins, but does not change position at all. Our symmetry with AddForceAtPosition truly is lost. In fact, Lockstep's solution is practically identical in effect to simply using AddTorque -- No matter what point at w$$anonymous$$ch you apply torque with $$anonymous$$s technique, not only will no net force be applied, but the same exact amount of torque will be applied. The only real difference is that, if you are not careful, the magnitude of t$$anonymous$$s torque will not equal the magnitude of the torque vector you plug in. There may also be some floating point uncertainty issues that arise from the mathematics involved in computing AddForceAtPosition, but these will be nominal.

The Lesson To Be Learned

Just use AddTorque -- don't even worry about what position you're applying torque to, it won't make a difference.

Just watch out! If you're using t$$anonymous$$s to simulate two objects being connected by, say, a motor, make sure that you take the appropriate steps to ensure conservation of linear momentum. In the case of an object centered on our pivot point (like our imaginary object), t$$anonymous$$s is as simple as making the imaginary object just a visual affront, and transferring its mass over to the main rigidbody. I'm not quite sure what would be involved with two objects connected at a pivot point that is mutually off-center-of-mass.

P.S: I actually came across t$$anonymous$$s issue myself doing propeller simulations too! Though in my case, I'm doing underwater ROV simulations, instead of quadcopter sims. :)

Comment

People who like this

0 Show 0 · 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.

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

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

AddRelativeTorque not rotating 1 Answer

τ = r × F, In unity3d/PhysX how do we define r? 1 Answer

AddTorque does not use ForceMode as expected (Different than AddForce) 1 Answer

Can I, someway, avoid centripetal force? 0 Answers

Figuring out the correct amount of torque to apply? 2 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