- Home /
How to make horizontal scene loop like JumpDown?
I'm trying to make the lines on the stage loop like in the JumpDown game. For this, I set limits according to the size of the screen and check the positions of the objects, this actually works, but it is a bit costly to do this for each object and I have performance problems because there are more than 200 objects on the stage that I need to check. Other than that, if the frame drops, objects can lose control.
private void Update()
{
if (work)
{
left_position = c_transform.position - c_transform.forward * (c_transform.localScale.z / 2 + left_position_offset);
right_position = c_transform.position + c_transform.forward * (c_transform.localScale.z / 2 + right_position_offset);
left_screen_position = camera.WorldToScreenPoint(left_position);
right_screen_position = camera.WorldToScreenPoint(right_position);
if (right_screen_position.x > 0 && left_screen_position.x < Screen.width)
{
inside = true;
}
if (right_screen_position.x < 0)
{
if ((right_object.right_position - spawn_right).magnitude >= minimum_distance)
WentOutOfLeft();
}
if (left_screen_position.x > Screen.width + 0)
{
if ((left_object.left_position - spawn_left).magnitude >= minimum_distance)
WentOutOfRight();
}
}
}
private void WentOutOfRight()
{
if (inside)
{
inside = false;
MoveToLeft(left_screen_position);
}
}
private void WentOutOfLeft()
{
if (inside)
{
inside = false;
MoveToRight(right_screen_position);
}
}
private void MoveToRight(Vector3 _right_screen_position)
{
spawn_right.y = transform.position.y;
Vector3 spawnPos = spawn_right;
spawnPos.x += c_transform.lossyScale.x / 2;
c_transform.position = spawnPos;
}
private void MoveToLeft(Vector3 _left_screen_position)
{
spawn_left.y = transform.position.y;
Vector3 spawnPos = spawn_left;
spawnPos.x -= c_transform.lossyScale.x / 2;
c_transform.position = spawnPos;
}
I am trying another method other than that. I'm putting two cameras side by side. One of them is base and the other is overlap. In this way, when I slide a single object to one side of the screen on the scene, it feels like there are two objects because the other camera renders it. This method is a very optimized method compared to the other, but the problem here is that the player must always be in the middle of the camera. Since there are two cameras, the actor appears on the object in one camera, but actually he is not there:
As a result, how can I make a system like in JumpDown game?