- Home /
Addforce to hinge Joint 2d on runtime
Hi, on my project i've two sprite on the stage, first one has hinge joint 2D enable and in runtime when i add a force it starts to make "pendulum" movement. On the second one i add the hinge joint 2d on runtime because it has to make a tween animation before, so on the callback of the animation i call a function that add the HJ2D and apply a force to make "pendulum" movement, here is the code:
void myFunction() {
HingeJoint2D myJoint = (HingeJoint2D)gameObject.AddComponent<HingeJoint2D>();
Vector2 ancore = new Vector2(0f,3.25f);
Vector2 connAncore = new Vector2(-1.97f,3.86f);
myJoint.anchor = ancore;
myJoint.connectedAnchor = connAncore;
myObject.GetComponent<Rigidbody2D>().AddForce(transform.right * 200);
}
from the ispector i see that the component is added and enabled, but the force will be never applyed.
i can't figure out why, please help me.
thanks so much
Your answer
Follow this Question
Related Questions
AddForce Impulse not moving the object 1 Answer
Acceleration and Max Speed on 2D Object 0 Answers
Bouncing Toward Target Point 0 Answers
How can I calculate the force required to contradict gravity?2d 2 Answers