We have a quite big 2D game at around 80% of its development completed (now it has 81 scenes). It was working fine on Unity 4.3, but we needed to upgrade to Unity 4.5 due to a pair of its new features.

The problem is that all the prefabs that were sliding platforms where a ball could bounce over them (using physics2D) now are broken. They use a Slider Joint 2D with motor and limits to make them move horizontally or vertically over the scene (a custom script makes them switch direction when a limit is reached). They are connected to a point in the scene (“Connected Anchor”) to make a line of movement.

Now they stop well before a limit is reached and if we look at their gizmo, the limits are still well calculated but now they seem to move with the object! We even tried to update the anchor in FixedUpdate to keep the limits on their place, but it’s a no-no.

So, might it be that SliderJoint2D behaves different than on 4.3? Or could it be broken in this build? Is some other developer using it in a similar way and noticed the problem?

Here is the code that calcs the limits (please notice that it worked flawlessly under 4.3):

```
void CalcSliderData()
{
JointTranslationLimits2D limits;
RaycastHit2D hit;
Vector2 startPos;
// Calc/load positions and limits
mSliderJoint.connectedAnchor = this.transform.position;
limits = mSliderJoint.limits;
if (Direction == MoveDirection.Horizontal)
{
// (cast ray rightmost and calc max limit)
startPos = this.transform.position;
startPos.x += this.renderer.bounds.size.x / 2 + 0.01f;
hit = Physics2D.Raycast(startPos, Vector2.right,
float.PositiveInfinity, 1 << 10);
if (hit.collider != null)
{
limits.max = (hit.point - startPos).x - BorderCollisionSensitivity;
}
else
{
mSliderDataIsOK = false;
print("ERROR: MovingWallHoriz " + this.name +
" can't find its rightmost limit!");
return;
}
// (cast ray leftmost and calc min limit)
startPos = this.transform.position;
startPos.x -= this.renderer.bounds.size.x / 2 + 0.01f;
hit = Physics2D.Raycast(startPos, -Vector2.right,
float.PositiveInfinity, 1 << 10);
if (hit.collider != null)
{
limits.min = (hit.point - startPos).x + BorderCollisionSensitivity;
}
else
{
mSliderDataIsOK = false;
print("ERROR: MovingWallHoriz " + this.name +
" can't find its leftmost limit!");
return;
}
mSlideUpperPos = mSliderJoint.connectedAnchor;
mSlideUpperPos.x += limits.max;
mSlideBottomPos = mSliderJoint.connectedAnchor;
mSlideBottomPos.x += limits.min;
}
else
{
// (cast ray upwards and calc max limit)
startPos = this.transform.position;
startPos.y += this.renderer.bounds.size.y / 2 + 0.01f;
hit = Physics2D.Raycast(startPos, Vector2.up,
float.PositiveInfinity, 1 << 10);
if (hit.collider != null)
{
limits.max = (hit.point - startPos).y - BorderCollisionSensitivity;
}
else
{
mSliderDataIsOK = false;
print("ERROR: MovingWallVert " + this.name +
" can't find its upper limit!");
return;
}
// (cast ray downwards and calc min limit)
startPos = this.transform.position;
startPos.y -= this.renderer.bounds.size.y / 2 + 0.01f;
hit = Physics2D.Raycast(startPos, -Vector2.up,
float.PositiveInfinity, 1 << 10);
if (hit.collider != null)
{
limits.min = (hit.point - startPos).y + BorderCollisionSensitivity;
}
else
{
mSliderDataIsOK = false;
print("ERROR: MovingWallVert " + this.name +
" can't find its lower limit!");
return;
}
mSlideUpperPos = mSliderJoint.connectedAnchor;
mSlideUpperPos.y += limits.max;
mSlideBottomPos = mSliderJoint.connectedAnchor;
mSlideBottomPos.y += limits.min;
}
mSliderJoint.limits = limits;
mSliderDataIsOK = true;
}
```