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 particlesmash · Jun 24, 2019 at 02:17 AM · torqueworkingaddforceatposition

Does anyone know the code behind the AddForceAtPosition function?

I am trying to do a little mini-project that involves air friction and the AddForceAtPosition function is exactly the function I need but I don't really like just using something I don't understand. I don't know how this function works in terms of applying torque correctly and I would like to know so I can better understand how torque is represented in code in general. If anyone knows the code behind it or has any idea as to what it may be, please let me know.

Comment
Add comment · Show 3
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 EDevJogos · Jun 24, 2019 at 04:27 AM 0
Share

@particlesmash I don't know the code, but most of unitys methods implementation is avaliable on GitHub: https://github.com/Unity-Technologies/UnityCsReference, i won't say all because i never read it all, but usually i find what i'm looking for.

avatar image Namey5 EDevJogos · Jun 24, 2019 at 06:36 AM 0
Share

Unfortunately, Unity rarely includes raw function implementations in the Git repository; ins$$anonymous$$d it includes references to hidden external implementations as to protect their intellectual property.

avatar image wolfulus Namey5 · Jun 24, 2019 at 06:47 AM 0
Share

That is for performance, not intellectual property since its only the physics engine. Also, it's probably adding force to force and cross(position - transform.position, force) to torque.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Namey5 · Jun 24, 2019 at 06:47 AM

https://www.enchantedage.com/node/68

This website has a pretty good summary of how a basic rigidbody works, including a basic implementation of the AddForceAtPosition method;

 public void ApplyForce (Vector3 forcePosition, Vector3 directionMagnitude) 
 {
     float lengthSquared = directionMagnitude.LengthSquared();
     if (lengthSquared < 1e-8f) return; // or use your own favorite epsilon
     Force += directionMagnitude;
     Vector3 distance = forcePosition - Position;
     Torque += Vector3.Cross(directionMagnitude, distance);
 }

So it essentially adds force to the centre of mass in the specified direction, and torque is calculated by finding the vector perpendicular to both the direction of the force and the direction of the point the force is being applied to.

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

109 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

Related Questions

Nose Diving Plane 1 Answer

Moving a rigid body on a plane applying forces 1 Answer

How to make 2d Vehicle/car physics in unity 3d 4.3 2d physics? 1 Answer

using torque to alighn an object with surface 0 Answers

Wheel Collider Stops Accelerating 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