Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 DCorboy · Apr 06, 2015 at 05:58 PM · rigidbodyaddforce

How to get force applied to object during FixedUpdate

In my game, I have colliders that trigger the 'levitation' of rigidbody objects. The problem is that when an object touches two collider triggers, the lifting force is doubled by the additive forces. The triggers do not overlap, but the objects can be touching two triggers at the same time, causing the problem.

What I would like is to examine the force already applied during this FixedUpdate. If the upward force is already equal or greater to the force needed, scripts would not add additional force as the goal is already 'acheived'.

Can folks suggest how I would solve this? Thanks!

Comment
Add comment · Show 14
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 Spinnernicholas · Apr 06, 2015 at 05:59 PM 0
Share

How are you checking for triggers?

avatar image DCorboy · Apr 06, 2015 at 07:09 PM 0
Share

The triggers are simple box colliders attached to the surfaces.

avatar image _Gkxd · Apr 06, 2015 at 08:43 PM 0
Share

The problem that I think you have is that whenever you collide with a trigger, you add a force, so when you collide with two or more, you add the force multiple times.

What you could do ins$$anonymous$$d is have a boolean, shouldLevitate, which you set to true whenever you collide with a trigger (and set to false when you aren't). If the boolean is true in your FixedUpdate, then apply the levitating force, otherwise don't. Doing it this way will only apply the force once, no matter how many triggers you collide with.

As far as I know, there is no easy way to get the net force on an object.

avatar image DCorboy · Apr 06, 2015 at 08:54 PM 0
Share

Yes, _Gkxd that is exactly the problem.

Unfortunately, the forces are not applied by the object to itself, but by other objects acting upon it (think of conveyor belts under the object that are lifting and moving it).

The object applying the force does not know what forces other objects have already applied to the object it is lifting.

avatar image Spinnernicholas · Apr 06, 2015 at 08:58 PM 0
Share

Ins$$anonymous$$d of having those other objects actually apply forces, have them queue up their forces and then have the main object deal with them in FixedUpdate().

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Spinnernicholas · Apr 06, 2015 at 06:01 PM

Create some sort of controller for the conveyor belts. When a conveyor belt triggers on an object, pass it to the controller. The controller will apply a force to all the affected object during fixed update.

==OLD== You should average all the force direction vectors and then multiple the average by the desired magnitude to get the final force vector to apply.

Comment
Add comment · Show 4 · 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 DCorboy · Apr 06, 2015 at 07:25 PM 0
Share

The problem is that I do not know the forces that have been so far applied to the object by other objects. $$anonymous$$y question is how I would deter$$anonymous$$e this?

avatar image Spinnernicholas · Apr 06, 2015 at 08:48 PM 0
Share

I'm guessing you are using onTiggerStay or something.

What you would do is queue up a list of triggers from your trigger collisions.

Then in FixedUpdate, you would process and clear the list and finally apply the force.

avatar image Spinnernicholas · Apr 06, 2015 at 08:50 PM 0
Share

Or you could do what _Gkxd suggested and have a boolean value. In the trigger function, you would set it to true. And then in fixedUpdate you would apply the force and reset the boolean to false.

avatar image DCorboy · Apr 06, 2015 at 08:58 PM 0
Share

Spinnernicholas, thanks for your thoughts. I am really hoping that you folks with more experience can tell me the right way to do this.

I am currently tracking objects using OnTriggerEnter/Exit and then processing that List during FixedUpdate. The problem is that the object can sometimes be touching two triggers that may both be applying force and I do not know how to deter$$anonymous$$e the forces that other (external) objects may have applied.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rigidbody-based spaceship? 1 Answer

Jumping with rigid body3d 1 Answer

rolling ball movement on different axis 0 Answers

push crate - works in editor, not on device 2 Answers

Rotation problem with spawning bullet 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