2d platform, 2 player, 1 camera

Hi, i have a question over here.
I am doing a 2d platform, with player 1 at the left side of the screen, and player 2 at the right side of the screen facing each other. The camera is showing both players. There is a maximum distance between player 1 and player 2 for the camera to show.
When player 1 moves backwards and reach the maximum distance, he cannot move backwards.

I uses Mathf.Clamp for both player1 and 2. But it seems that when player1 moves backwards, he is dragging player2 along too.

How do I do that?
Thanks.

use a if command and the Vector3.Distance.

-addon:
When the player1 moves backwards, and reach the maximum distance between both players, there was like an invisible wall, the player can’t move anymore backwards. how?

This is a simple version of it.
then the distance also should relay on the camera distance, but i trust that you can figure out that part. :stuck_out_tongue:

PlayerScript.js

var speed = 3.0;
//var rotateSpeed = 3.0;

function Update ()
{
    var controller : CharacterController = GetComponent(CharacterController);

    // Rotate around y - axis
    //transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    
    // Move forward / backward
    var forward = transform.TransformDirection(Vector3.forward);
    var curSped = speed * Input.GetAxis ("Horizontal");
    controller.SimpleMove(forward * curSped);
}

@script RequireComponent(CharacterController)

Arena.js

var Player1: GameObject;
var Player2: GameObject;

var MaxDistance: float;

function Start() {
  Player1 = GameObject.Find("player1");
  Player2 = GameObject.Find("player2");	
}

function Update () {
  var distance = Vector3.Distance(Player1.transform.position, Player2.transform.position);
  if (distance > MaxDistance) {
    Player1.transform.position.z = Player2.transform.position.z + -MaxDistance+0.001;	
  }	
}

But i guess you and thinking of a tekken like game, so what i would do is, have the camera’s distance to go out to a point and have a box colliders on each end, with a width of lets say 15, so and when the players come closer to each other the camera simply zooms in…

k, thanks. i will go and try it now.