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 Waliactico · Apr 05, 2013 at 10:12 AM · physicstimeforcedeltatime

Force mode and delta timing

I'm trying to make a throwable object that is throwed by pressing a key. I have been reading a lot about this, but I see nothing but contradictory explanations... What I want to do is apply a force in a single FixedUpdate cycle, so in the next ones the object would go on by itself. So, do I need to use ForceMode.Force or ForceMode.Impulse? And also very important, does this force need to be multiplied by Time.deltaTime in any of this force modes?

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
Best Answer

Answer by ByteSheep · Apr 05, 2013 at 05:42 PM

I personally use rigidbody.AddForce for this sort of thing.
You can apply the force over one frame and the physics engine will automatically carry on the movement of the object.
So you could add force over a single frame - this also means that you shouldn't have to worry about Time.deltaTime..
An example of using rigidbody.AddForce:

 if(Input.GetMouseButtonDown(0))
 {
   ThrowObject.rigidbody.AddForce(Vector3(0, 0.5, 1) * 100);
 }

Ofcourse the throw object will need a rigidbody component for this to work correctly.

Comment
Add comment · 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 Waliactico · Apr 05, 2013 at 06:05 PM 0
Share

Yes, I'm using AddForce. But, reading Unity's documentation about force modes, I wasn't sure if I should use Force (the default one) or Impulse. If your example is correct by calling it on just 1 frame, then I don't know the difference between those 2 force modes... http://docs.unity3d.com/Documentation/ScriptReference/Force$$anonymous$$ode.html

avatar image ByteSheep · Apr 05, 2013 at 06:14 PM 0
Share

Ah ok I see what you mean, that is a bit confusing.
The code i use is this:

 obj.rigidbody.AddForce(Vector3(0, 0.2, 2) * force, 0);

And I call this only once when a keyDown event is triggered.
The force is only applied over one frame and acts more like a "push" rather than a continues force that is being applied.
It gives a nice throw curve though.
Here I am using Force$$anonymous$$ode.Force, I have never tried Force$$anonymous$$ode.Impulse.
Not entirely sure what the difference is there, but I'd probably just create a test scene and try them both out..

avatar image Waliactico · Apr 05, 2013 at 06:22 PM 0
Share

If using Force$$anonymous$$ode.Force in 1 frame is correct, I think it's just a matter of testing to see which mode fits the best. Anyway, delta ti$$anonymous$$g is not necessary using either mode, isn't it?

avatar image ByteSheep · Apr 05, 2013 at 06:28 PM 0
Share

When only applying the force over one frame you won't need to use deltaTime.
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html?from=Force$$anonymous$$ode
The documentation says to use FixedUpdate() rather than Update() when applying force over several frames though.
So that should effectively do the same as multiplying by deltaTime.

avatar image ByteSheep · Apr 05, 2013 at 06:33 PM 0
Share

Here is something interesting:
http://docs.unity3d.com/Documentation/ScriptReference/ConstantForce.html
"Rigidbody.AddForce applies a force to the Rigidbody only for one frame, thus you have to keep calling the function. ConstantForce on the other hand will apply the force every frame until you change the force or torque to a new value."

Show more comments

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

11 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

Related Questions

When to apply delta time for framerate independence. 1 Answer

Character Controller meets Rigidbody 1 Answer

add force to object that has 2 different rigid bodies 0 Answers

how to change the filedof view slowly 2 Answers

Framerate Independent Firing Rate (delta time?) 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