Question by
bulletb · Apr 07, 2017 at 02:53 PM ·
rigidbody2dphysics2daddforcehingejoint2d
Unable to AddForce on a game object containing a RigidBody2D and a HingeJoint2D?
I have a game object which contains a HingeJoint2D and a RigidBody2D. I've also attached the following debugging script:
void FixedUpdate() {
if (Input.GetKey(KeyCode.Space)) {
GetComponent<Rigidbody2D>().AddForce(Vector2.up * 100f);
Debug.Log(GetComponent<Rigidbody2D>().velocity);
}
}
I've found that when I have the HingeJoint2D enabled, the script does not add force to the RigidBody2D. However, if I disable the HingeJoint2D, the script adds the force as expected.
Why is this?
Comment
Best Answer
Answer by MelvMay · Apr 07, 2017 at 03:01 PM
What is the HingeJoint2D.connectedBody set to? If it's not set to anything then you're asking that its connected to the world. The Rigidbody2D therefore cannot move as you've just asked it to rotate around that world point.
Ahh thank you, that was exactly the piece of information that I did not know. It seems after setting a connectedBody, it moves as expected.