- Home /
Possible to apply forces/rotations to a rigid body without other rigid bodies effecting it's physics?
As the title suggests, I was wondering what the best way is to prevent other rigid bodies from effecting my game object, but still be able to apply forces and rotations on that object myself. One possible solution is to give the rigid body infinite mass, but I'm not sure how to do that (in some physics engines for example, a mass of zero = infinite mass, but I don't know if this is true in Unity).
The problem is that if I set it as a kinematic rigid body, I can no longer apply forces / angular velocity on that body. I don't want to have to update the transform component manually, because that feels too much like a hacked solution, and it will not work as well with the rest of the game's physics.
Oddly enough, I can set the angular velocity variable for 2D kinematic bodies manually and it surprisingly works (maybe it's a bug?), however I need this functionality for 3D bodies.
Answer by Owen-Reynolds · Apr 26, 2016 at 07:33 PM
It actually works fine to set a 3D object's angularVelocity (and velocity) by hand. I've done it in several reasonably well-tested places. Should probably be done in fixedUpdate, but I've done it in Update and it worked.
But, it may not be perfect. It's possible in the physics step it may hit something, slow a bit, and not rotate/move the full amount. Giving it a very high mass should reduce this to almost nothing.
= = = = = =
The official solution is rigidbody .MoveRotation on a Kinematic object. It forces you to go there, like changing a transform directly, but tries to apply proper physics to anything it hits. There's also rigidbody.MovePosition.
The last time I tested it (a few years ago) it seemed to work pretty well. Of course, the drawback is that it's not fire-and-forget, like setting velocity once at the start.
Answer by Vagonn · Apr 26, 2016 at 07:38 PM
http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
http://docs.unity3d.com/ScriptReference/Physics.IgnoreLayerCollision.html
This makes objects just go through each other (which may be what the OP really wants.)
But from the OPs infinite mass comment, I think the object should affect other things, but not be changed itself -- like it was made of super-dense material.
Your answer
Follow this Question
Related Questions
Drag area from HUD 1 Answer
Compare rigidbody.centerofMass with go.rigidbody.centerofMass ? 0 Answers
Kinematic rigidbody only triggering once 0 Answers
Constantly checking OnCollisionStay 2 Answers
Kinematic rigidbody movement. 2 Answers