# 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?

### People who like this

### Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. **Please note, Unity Answers is now in read-only so we can prepare for the final data migration.**

For more information and updates, please read our full announcement thread in the Unity Forum.

### Follow this Question

### Related Questions

How to flip 2d chacacter built with joints? 0 Answers

How can I make HingeJoint2D more flexible? 0 Answers

2D active ragdoll holding object 1 Answer

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