- Home /
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!
The triggers are simple box colliders attached to the surfaces.
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.
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.
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().
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.
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?
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.
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.
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
![](https://koobas.hobune.stream/wayback/20220613192337im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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