Hello,
I have my player GameObject, towing a chain of other objects using SpringJoints, all works well & good. They are flying in a pseudo-2D world, which is a finite size. When the player goes past a certain limit near the edges, I translate everything across to the other side, so it’s like having a globe world - again, this works fine for the player. Trouble is, the towed objects don’t seem to translate properly, and spend a few frames whizzing about as their spring joints readjust, so it looks a bit odd. The basic code is -
Player (on FixedUpdate() ):
float posX = transform.position.x;
float posZ = transform.position.z;
bool hasCircumnavigated = false;
Vector3 shift = Vector3.zero;
if (posX < worldXLimitLeft) {
shift = new Vector3(worldWidth, 0f, 0f);
hasCircumnavigated = true;
} else if (posX > worldXLimitRight) {
shift = new Vector3(-worldWidth, 0f, 0f);
hasCircumnavigated = true;
}
if (posZ < worldZLimitBack) {
shift = new Vector3(0f, 0f, worldDepth);
hasCircumnavigated = true;
} else if (posZ > worldZLimitFront) {
shift = new Vector3(0f, 0f, -worldDepth);
hasCircumnavigated = true;
}
if (hasCircumnavigated) {
transform.Translate(shift);
trailingObjectsManagerScript.RelocateTrailingObjects(shift);
}
Trailing objects:
public void RelocateTrailingObjects(Vector3 theMovement) {
foreach (GameObject theObject in towedObjects) {
theObject.transform.Translate(theMovement);
}
}
It’s as if the spring joint is affecting the translation somehow. If anyone knows what’s going on, I’d appreciate some advice!
Thanks