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
1
Question by runerask · May 19, 2014 at 11:43 PM · physicsrigidbodyvelocity

How to simulate AddForce?

Hello Unity Community!

I have some questions about rigidBodies and about AddForce specifically.

Im having a issue, where i want to pre-simulate paths that a rigidBody takes for UI/Feedback purposes, but i am having a hard time "getting it right".

So for my rigid body lets say for brevity sake that i do could do a simple thing like:

 newRigidBody.transform.position = startPosition;
 newRigidBody.rigidBody.AddForce(direction*power);

Somewhere else in my code i want to know what that would mean before it happens. So every update i do something like:

     //Calling this every frame:
     private void CalculatePath(Vector3 StartPosition, Vector3 InitialVelocity)
     {
         int plots = 20;
         float t = Time.fixedTimeStep;
         Vector3 pos = StartPos;
         Vector3 vel = InitialVelocity; 
         for(int i = 0; i < plots;i++)
         {
             //As far as i can tell from the documentation "Adding Force" is just
             // rigidBodyMass*(force)*t^2 ? Remember im trying to replicate what
             // happens to my rigidBody
             vel = vel + 1*(CalculateAffectors(pos))*t*t;
             pos = pos + vel * t;
         }
     }
 // Here i get everything that my rigidBody will be "pulled" by on this path (gravity) 
 private void CalculateAffectors(Vector 3 position)
 {
     Vector3 force = Vector3.zero;
     for(int i = 0; i < Affectors.Length; i++)
     {
         if(Vector3.Distace(Affectors[i].position, position) < minDistance)
         {
           Vector3 direction = Affectors[i].position - position;
           force = force+(direction/direction.sqrMagnitude * Affectors[i].mass);
         }
     }
     return force;
 }

So first of all, this does not actually plot points that follow the path that the rigidBody takes (which at the bottom the line is my problem), but my questions are:

A) Since i am using AddForce() - how can i deduct my initial velocity from that? (since it's over time i am unsure - doing "CalulatePath(pos, mass*(direction*power)*t*t" does not work.

B) When a rigidBody is being affected by several AddForce()(Gravity for example) calls every fixed update, how can i reliably simulate that in one loop? Or rather the logic used to move my rigidBodies is how i want it i.e using addForce every frame - how to calculate that as a velocity change in my "plotting".

C) is my math even right? The problem right now is that it looks "almost" right as in, my paths are very close to what points i can query during the rigidBody's traversal, but it seems they get off by a a larger and larger margin (1:1, 1:1.1, 1:2, 1:10 ect).

I tried applying the affectors "one at a time", tried firering my rigidBodies with ForceMode.VelocityChange (since then the initial velocity of my rigidBody should be the same as what i can pass into my Paths function - but it's not, far from it hehe).

I think i have been looking at this too much maybe, switching around ordering / numbers / vectors and at this point, you guys are my only hope!

Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jeff-Kesselman · May 20, 2014 at 12:19 AM

Unity uses PhysX, which is a very complete and complex physics simulation.

If you want to know about how it calculates motion, you can google PhysX but be prepared for heavy and complex math.

If you want to be able to predict simple physics behavior its probably better to create your own simple f=MA physics model.

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

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

Throwing knife doesn't throw correctly 0 Answers

Apply Gravity to Car Physics 0 Answers

Why does writing to rigidbody.velocity after AddForce stop my rigidbody moving? 4 Answers

Rigidbody cube randomly stops moving? 1 Answer

Throwing objects with a fixed joint? 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