# Change 2D Player position based on Enemy Position. Hinge Joints and Angle Limits.

Hi there!

I have a stickman ragdoll that's hold together by a couple of Hinge Joints with angular limits. There's also an enemy who can change his position so it can be on the left side of the player or the right side of him.

Both stickman's layout is this:

```
Empty GameObject:
-Head
-Torso
-ArmR
-ArmL
-LegR
-LegL
```

The `ArmR`

and `ArmL`

has an angular limit of `0`

min, `90`

max.

What's the easier way to inverse stickman's angular limit or rotate the stickman to look at the enemy?

This is with what I've come but it doesn't work as intended:

```
public void ChangePos(float pos)
{
HingeJoint2D hinge;
JointAngleLimits2D limits;
JointMotor2D motor;
if (pos > 0 && GetPlayerCanMove()) // -> right
{
Debug.Log("Changed Pos!");
hinge = head.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = 20;
hinge.limits = limits;
hinge = legUpperRight.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = 90;
hinge.limits = limits;
hinge = legUpperLeft.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = 90;
hinge.limits = limits;
hinge = legRight.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = limits.max * 30;
hinge.limits = limits;
hinge = legLeft.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = 30;
hinge.limits = limits;
}
else if (pos < 0 && GetPlayerCanMove() && weaponLeft.activeSelf)
{
hinge = head.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = -20;
hinge.limits = limits;
hinge = legUpperRight.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = -90;
hinge.limits = limits;
hinge = legUpperLeft.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = -90;
hinge.limits = limits;
hinge = legRight.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = -30;
hinge.limits = limits;
hinge = legLeft.GetComponent<HingeJoint2D>();
limits = hinge.limits;
limits.max = -30;
hinge.limits = limits;
}
}
```

Is there an easier way to do this?

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

How can I make HingeJoint2D more flexible? 0 Answers

2D drag and throw ragdoll physics 0 Answers

How to make a puch to open door 2D 0 Answers

Ragdoll 2D hinge joint limit issue 0 Answers

Can't see Hinge Joint 2d anchor points 2 Answers