RTS Camera panning

Hey, can someone help me with this? So I’m making an RTS game and I’m making the camera panning thing. I have a problem with the edge panning the Y is working but the X is not. The arrows are working perfect but the edge panning of the X is messed up.

This is the code that i use.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseMovementCamera : MonoBehaviour {

    public float panSpeed = 20f;
    public float panBorderThicknes = 15f;

    void Update() {
        Vector3 pos = transform.position;

        if (Input.mousePosition.y >= Screen.height - panBorderThicknes)
            pos.z += panSpeed * Time.deltaTime;

        if (Input.mousePosition.y <= panBorderThicknes)
            pos.z -= panSpeed * Time.deltaTime;

        if (Input.mousePosition.x >= Screen.width - panBorderThicknes)
            pos.x += panSpeed * Time.deltaTime;

        if (Input.mousePosition.x <= panBorderThicknes)
            pos.x -= panSpeed * Time.deltaTime;

        transform.position = pos;

I tested your code on my machine and it works perfectly when attached to the camera. My guess is that something else in the scene is interfering.

Try checking the following:

  • Is the camera used in any animations, if so the animation could be overriding the script?
  • Is there another script that references the camera and alters it’s position?
  • Have you enabled Cinemachine at all? This will override and scripts attempting to reposition the camera.