Hello Everyone!
I am making a game which has a RTS camera view, basically a top-down camera view. I have made the camera move, scroll and rotate but when it rotates, it doesn’t really feel the movement. If i rotate the camera 180 degrees, the movement will be reversed. How can stop the reverse movement when rotating the camera
Camera Movement Script:
public float panSpeed = 20f;
public float panBorderThickness = 10f;
public Vector2 panLimit;
public float scrollSpeed = 20f;
public float minY = 20f;
public float maxY = 120f;
void Update() {
Vector3 pos = transform.position;
if (Input.GetKey(KeyCode.W))
{
pos.z +=panSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S))
{
pos.z -=panSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
pos.x +=panSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.A))
{
pos.x -=panSpeed * Time.deltaTime;
}
float scroll = Input.GetAxis("Mouse ScrollWheel");
pos.y -= scroll * scrollSpeed * 100f * Time.deltaTime;
pos.x = Mathf.Clamp(pos.x, -panLimit.x, panLimit.x);
pos.y = Mathf.Clamp(pos.y, minY, maxY);
pos.z = Mathf.Clamp(pos.z, -panLimit.y, panLimit.y);
transform.position = pos;
}
}
Camera Rotation Script:
public float speed = 3.5f;
private float X;
private float Y;
void Update() {
if(Input.GetMouseButton(0)) {
transform.Rotate(new Vector3(Input.GetAxis("Mouse Y") * speed, -Input.GetAxis("Mouse X") * speed, 0));
X = transform.rotation.eulerAngles.x;
Y = transform.rotation.eulerAngles.y;
transform.rotation = Quaternion.Euler(X, Y, 0);
}
}
}