Hi everybody,
I’m trying to create an 2D RTS Game like Warcraft 2 with isometric map.
I have some problems to move correctly my camera.

When I move down my mouse the camera is out of the map . I would like increase xmin to resolve the problem.
but when i increase xmin it doesn’t work and it’s not smoothly.
Here the code of my camera
public class CameraManager : MonoBehaviour {
public float speed = 0.5f;
private Vector3 startPos;
private bool moving;
private float xmin = 450;
private float xmax = 22031;
private float ymin = -3713;
private float ymax = 160;
void Start() {
Screen.SetResolution (1280, 720, true);
}
void FixedUpdate() {
if (Input.GetMouseButtonDown (1)) {
startPos = Input.mousePosition;
moving = true;
}
if (Input.GetMouseButtonUp (1) && moving) {
moving = false;
}
if (moving) {
float vertical = Input.GetAxis("Mouse Y");
float horizontal = Input.GetAxis("Mouse X");
// Clamp Value for camera
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - startPos);
Vector3 move = new Vector3 (pos.x * speed, pos.y * speed,0 );
transform.Translate (move, Space.Self);
Vector3 clampedPosition = transform.position;
Debug.Log(xmin);
clampedPosition.x = Mathf.Clamp (transform.position.x, xmin, xmax);
clampedPosition.y = Mathf.Clamp (transform.position.y, ymin, ymax);
transform.position = clampedPosition;
}
}
and here the code of my map:
public class GameManager : MonoBehaviour {
public Sprite GrassTile;
public GameObject Bricks;
public GameObject Panel;
public GameObject Mushroom;
public GameObject Root;
public GameObject Flowers;
public TextAsset textFile;
private int tileType;
private const int columns = 448;
private const int rows = 248;
public int[,] mapData = new int[columns,rows];
void Start () {
// Read and split text
char[] Separator = new char[] {',','\n'};
string text = textFile.text;
string[] lines = text.Split (Separator);
int index = 0; // index for read and parse lines array
int x = 0;
int y = 0;
int isoX = 0;
int isoY = 0;
for(int j=0; j < rows; j++) {
for(int i =0; i < columns; i++){
mapData[i,j] = Int32.Parse(lines[index++]);
x = i * 32;
y = j * -32;
isoX = (x - y);
isoY = (x + y) /2;
/*if (mapData[i,j] == 46) {
Instantiate(GrassTile,new Vector3(isoX, isoY, 0),Quaternion.identity); // Orthographics
}*/
var tile = new GameObject();
tile.transform.position = new Vector3(isoX,isoY,1);
var spriteRenderer = tile.AddComponent<SpriteRenderer> ();
spriteRenderer.sprite = GrassTile;
tile.name = "Grass" + tile.transform.position;
if (mapData[i,j] == 62) {
Instantiate(Flowers,new Vector3(isoX,isoY, 0),Quaternion.identity);
}
if (mapData[i,j] == 135) {
Instantiate(Root,new Vector3(isoX,isoY,0),Quaternion.identity);
}
if (mapData[i,j] == 282) {
Instantiate(Bricks,new Vector3(isoX,isoY ,0),Quaternion.identity);
}
if (mapData[i,j] == 103) {
Instantiate(Panel,new Vector3(isoX,isoY,0),Quaternion.identity);
}
if(mapData[i,j] == 280) {
Instantiate(Mushroom,new Vector3(isoX,isoY,0),Quaternion.identity);
}
}
}
}
// Update is called once per frame
void Update () {
}
}
Sorry for my bad english ![]()
Thank you for your help.
Bye