Hinge Joint 2D not working when Rigidbody is Kinematic
I'm making a 2D pinball game in which the flippers are animated with a Rigidbody 2D and Hinge Joint 2D components. All works fine when the Rigidbody is set to Dynamic, but when I change it to Kinematic, the flipper doesn't respond to input. It doesn't rotate.
I think it's better if the flippers were Kinematic as there's no need for them to calculate physics. All they need to do is provide something for the ball to bounce off of, and I think they don't need to be included in the Physics 2D calculations.
What could I be missing that's preventing the flippers from rotating when I change them to Kinematic? Any help is welcome!
Answer by VRlunatic · Oct 06, 2019 at 11:18 AM
Also, maybe this matters: I'm using the motor function to move the flippers. Maybe they only work when the hinge joint is dynamic. How to rotate the flippers kinematically? Thanks.
Answer by prabhjeets · Oct 11, 2019 at 05:19 AM
I have almost the exact same problem and am unable to move the object by modifying the motor speed in script. Been banging my head against Google searches for a couple of days now with no luck. Below is my FixedUpdate method. I can see the speed being set on the motor of the hinge in the debug statement but object does not move.
void FixedUpdate()
{
if (isKeyPress)
{
myMotor.motorSpeed = 1000;
myHinge.motor = this.myMotor;
myHinge.useMotor = true;
Debug.Log("Motor Speed: " + myHinge.motor.motorSpeed);
}
else
{
myMotor.motorSpeed = -1000;
myHinge.motor = myMotor;
}
}
That's because you can only use the motor function when the rigidbody is set to dynamic. The motor function has to use physics. When you set the rigidbody to kinematic (as I want it because it's more efficient) then you cannot use the motor function for rotation but have to do it a different way, such as with transform.rotate or with a tween. I'm using a tween from DOTween which works well, as I described above. The only problem is that the ball is hit too hard, as you cannot specify the force when using kinetic simulation. I hope someone offers an answer to this. I am thinking I have to somehow dampen the physics material, I'll check out the settings when I get home.
Your answer
Follow this Question
Related Questions
Unable to AddForce on a game object containing a RigidBody2D and a HingeJoint2D? 1 Answer
2d gameobjects stuttering 0 Answers
Chain made out of 2D Hinge Joints isn't moving around, also it stretches weirdly 0 Answers
Hit from kinematic rigidbody2d 1 Answer
Hingejoint2d's connected body unaffected by joint, spinning wildly (video) 0 Answers