- Home /
Disabling a rigidbody.
How do I disable a rigidbody? If I do rigidbody.active, it tells me to use enabled instead. But rigidbody doesn't have enabled property.
Answer by Jessy · Mar 02, 2011 at 08:44 PM
What does "disable" mean, to you? Changing to kinematic with a trigger collider is the closest you can come, other than disabling the entire Game Object or destroying the component.
Jessy is right, I tried lots of approaches and the only one that seems to work is essentially what he suggested, to "turn off" physics for a Rigidbody just do:
// This code definitely works in Unity 5.2
// you should check ( rb != null ) before using rb...
Rigidbody rb = gameObject.GetComponent< Rigidbody >();
rb.detectCollisions = false;
rb.is$$anonymous$$inematic = true;
this will stop the physics system calculating physics interactions for the object & it will remain still unless you move it. Just do the opposite to turn it back "on".
If you want to do the same thing for a trigger, you can just disable the collider using Collider.enabled = false & re-enable by setting it to true.
Note that any behaviour you have in your code that relies on detecting the enter & exit of a collision or a trigger might well break when using these techniques - when you set Rigidbody.detectCollisions or Collider.enabled to false that will NOT call the OnCollisionExit / OnTriggerExit.
Answer by Squarefish · Dec 14, 2012 at 03:10 PM
I have a similar problem with rigidbodies. My game engine as far as collisions are concerned are using the Collision() methods, which always require convex rigidbodies (as far as I can tell)
My problem is whilst handling all velocities, positioning myself that the rigidbodies interfere with eachother as they are conscript of Unity3d's physics engine. This occurs rarely as I'm using settings which minimise reactions from the physics engine, however...
It's bad enough having to use rigidbodies to use the Collisions class functions but is there a way to totally disable physics?
(The previous answer here is a little inadequate as it recommends disabling the GameObject or destroying a needed component)
huh? if you don't want to use a game engine, and don't want to use PhysX, then don't use a game engine. just program using Corona or something else, or just move images around raw as an XCode project.
you talk about calculating your own velocities, positions etc. that's just kind of weird. you just use PhysX to do all that.
if you don't want to use rigidbodies - don't use them. if you don't want to use colliders - don't use them.
Answer by Squarefish · Dec 14, 2012 at 03:40 PM
I like Unity3d.. personally I feel a bit beaten back by your comment, and so would others.
I wanted to calculate all my own velocities and positions because of the nature of my project.
I have no idea what you mean by using XCode.
I've seen similar posts to mine about collisions not being accessible without rigidbodies. This is my main complaint of Unity3d and I've coded a workaround if there is no solution for turning physics off. I do want to use Colliders. Not Rigidbodies.
By god, there are many reasons to use Unity3d... not only for PhysX!
Your post is totally deconstructive from a programming point of view.
it could be your comment is misunderstandable, no offense.
In any event you now say "I wanted to calculate all my own velocities and positions because of the nature of my project."
If so - no problem at all. Don't use PhysX, rigidbodys or colliders.
If I understand you, you want to use colliders YES but NOT use rigidbody to move the item, but you want to move it yourself - but - even though you're moving it yourself you want the colliders to work ?!?
Is that about correct? If so, the answer is simply "oh you can't do that"
Just move them yourself (as you say) and make your own colliders.
Further, let's go back to this statement
"I wanted to calculate all my own velocities and positions because of the nature of my project."
just FTR, it's sort of a mathematical law that - there is no need to move them yourself. TBC, there is nothing you can't do (by moving them yourself) that you can't achieve by having PhysX move them.
(TBC I've many times "moved things myself" in rigs, and indeed you can always just use PhysX to move them, ins$$anonymous$$d, for the same result. But the point is no, it's not possible to "move around" colliders yourself, and expect PhysX to work - you can't do that. You'd have to write your own colliders.)
there are many strange rigs you can build using Unity,
for example
http://answers.unity3d.com/questions/299407/character-collision-of-walls-inside-moving-ship.html
but in any event you can't use colliders unless you're letting physX move it.
FYI
"I wanted to calculate all my own velocities and positions"... once you set the velocity of something, the position is deter$$anonymous$$ed (unless you don't believe in eg Peano's aioms)
although it's "not normal" to do so, you can freely set the veolocity of stuff in physX (ie, of rigidbodys) as you wish. this is a "normal" if you will advanced technique (to make comets fly around stars or whatever)
Answer by Squarefish · Dec 14, 2012 at 05:21 PM
I'd like to apoligise and let you know the point I raised earlier, was fallible.
Although you can't "turn off physics" for using Collider function classes and you do need a Rigidbody:
You can turn effects of physics off by clicking in the Rigidbody dialog freeze positions X,Y,Z and likewise for freeze rotations.
You can edit the positions and rotations by coding them in the usual way, whilst using this feature.
there's no need to apolgise, for goodness sake!
BTW if possible please just click the S$$anonymous$$ALL CO$$anonymous$$$$anonymous$$ENT BUTTON to comment rather than using a new "answer"
you can do what you say but people will think you're a pervert :)
Just FTR you can always achieve the same by just setting the velocity of the rigidbody (every FixedUpdate, if you particularly want to). But ENJOY !
Answer by davidnibi · Feb 08, 2020 at 10:29 AM
yourRigidbody.constraints = RigidbodyConstraints.FreezeAll;
or
yourRigidbody.constraints = RigidbodyConstraints.FreezePosition;
yourRigidbody.constraints = RigidbodyConstraints.FreezeRotation;
Your answer
![](https://koobas.hobune.stream/wayback/20220613111030im_/https://answers.unity.com/themes/thub/images/avi.jpg)