- Home /
How to prevent a rigidbody from pushing other rigidbodies?
I have a first-person controller that can carry rigidbodies in front of the camera. The rigidbody pushes other rigidbodies when hitting them. This allows the player to move very heavy rigidbodies too easily. How can I prevent this?
The rigidbody-carrying code I'm using can be found on the bottom of the first page of this topic, it's made by username85.
Answer by gregzo · Apr 12, 2012 at 03:16 PM
set your rigidbody's isKinematic property to true!
The carried rigidbody's? Doesn't seem to work. Here's my code: http://pastebin.com/pJCe7kRg
I'm pretty sure you could set the rigidbody's mass to 0, or at least a very small number, and it shouldn't be able to push. Not sure though, haven't tested. Also, probably wouldn't be a very viable solution because it would affect physics calculations for your rigid, but it's worth a shot.
"rigidweight = rigidbody.mass; rigidbody.mass = 0.0000001;" when picking up the rigidbody and "rigidbody.mass = rigidweight;" when dropping it? Nope, it still pushes all other rigidbodies with the same force. The rigidbody that's being carried is moved around with "rigidbody.$$anonymous$$ovePosition(transform.position + transform.forward * holdDistance);", does this have something to do with the problem?
$$anonymous$$ovePosition tells it to go there, no maater what. To get a "physics-based" push effect, set velocity.
The problem is, characterControllers and physics-pushing don't mix (if your FP controller is charController based.) $$anonymous$$aybe look up hacks to make a CC push things (using OncharColliderHit) and adapt that to include the carried object.
The FP controller is a Character Controller, yes, and I've attached a script to it that enables it to push rigidbodies (I found it here: http://answers.unity3d.com/questions/17566/how-can-i-make-my-player-a-charactercontroller-pus.html). But what does this have to do with the collision of two rigidbodies? The character controller is not part of it. Thanks anyway.
(Btw, I tried setting the carried object's detectCollisions to false but it's a bit coarse solution. Also, when detectCollisions is set to true when the item is inside another object they both fly high in the air.)
Your answer
Follow this Question
Related Questions
Making Colliders/Triggers or Rigidbodies move a Character Controller 5 Answers
How to make certain rigidbody2d's not able to push other rigidbody2d's? 2 Answers
Get angle from impact 2 Answers
Collisions between two rigidbody's and scripting collisions problem 2 Answers
Rigidbody stuck in colliders when moving and ricosheting. 0 Answers