Attach Kinematic Collider To Non-Kinematic Collider
I have a non-kinematic rigid body (we will call this the vehicle), I have a non-kinematic rigid body attached using a hinge joint to that non-kinematic rigid body (we will call this the motor). The motor colliders should not collide with the vehicle colliders, and instead I want to attach a kinematic rigidbody (this will just be a copy of all the colliders of the vehicle rigidbodys' colliders) to the vehicle such that in anyway the non-kinematic rigid body moves, the kinematic rigid body moves rotates etc to the exact same place, and that movement should happen during the internal physics update (moving it in the fixed update wont work.) I have tried attaching the kinematic rigid body using a fixed joint, that stops the vehicle from being able to move at all (it seems that kinematic body takes precident or smth), I have tried parenting the kinematic body to the non kinematic body, but then when the motor hits the kinematic rigidbody it just phases through and also it ends up adding forces to the vehicle (as if it was non-kinematic... very weird). The end result i want is that when the motor hits the vehicle it is attached to, it will just stop moving in that direction, but it will add no force to that vehicle, so vehicles cant catapult themselves, but if the motor hits the ground or another vehicle, it can still add forces to them etc.
Any help will be greatly appreciated. :)
Answer by Edy · May 24 at 09:04 AM
Moving your kinematic body from FixedUpdate is the only way. It will be one physics frame behind, but there's no other way to do that in Unity. Ensure to use Rigidbody.MovePosition and Rigidbody.MoveRotation from FixedUpdate to move your kinematic body. Any other method (i.e. using the Transform) may cause issues.
You can use Physics.IgnoreCollisions to prevent two specific colliders to collide, but allow collisions with other colliders.
As an addon to the almost sub question of having a hinge hit something but not apply any force to it, I've found that ModifiableContactPair, and setting bounciness on contacts to 0 does a fairly good job, however it does seem at high speeds or small colliders, colliders attached to hinges will push and pass through the collider.
Your answer
Follow this Question
Related Questions
Making a rigidbody "immune" to reacting with another specific rigidbody? 0 Answers
rigidbody iskinematic issue 1 Answer
how to prevent a kinematic rigidbody from going through static colliders 0 Answers
Freezing an object and keeping it's velocity 1 Answer
What is the point of MovePosition()? 1 Answer