- Home /
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;
}
}
Answer by AaronXRDev · Nov 09, 2018 at 06:46 PM
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.
This is the first script that I've made for the game. I don't really know what's wrong. No, I haven't enabled Cinemachine. And it's not used in any animation. @EgoAnt
If you want, you could post the project on a dropbox or something and I could give it a look.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Click to Move With Navmesh 0 Answers
how do i Disable and Enable buttons? 2 Answers
How to access variables from an object based on location? C# (Pic inside) 1 Answer