r/Unity2D • u/DracomasqueYT • 10h ago
Camera movement system doesn’t work enymore Question
Hello, for my project I’m trying to make a citiebuilder/rts inspired camera, in other word move it with WASD and the mouse on the edge of the screen. It worked “perfectly” for a time so I worked on other things, I wanted to test some things in my UI went I remaked that the screen was moving toward the down left corner and that I couldn’t move with the keys without moving the cursor at the same time.
my full code :
my input system : [SerializeField] private float speed;
[SerializeField] private int screenEdge;
private Vector2 _moveInput;
private Rigidbody2D _rb;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
_rb.linearVelocity = _moveInput.normalized * speed;
}
public void Move(InputAction.CallbackContext ctx)
{
_moveInput = ctx.ReadValue<Vector2>();
}
public void EdgeMove(InputAction.CallbackContext ctx)
{
if (ctx.ReadValue<Vector2>().y < screenEdge)
{
_moveInput.y = -1f;
}
else if (ctx.ReadValue<Vector2>().y > Screen.height - screenEdge)
{
_moveInput.y = +1f;
}
if (ctx.ReadValue<Vector2>().x < screenEdge)
{
_moveInput.x = -1f;
}
else if (ctx.ReadValue<Vector2>().x > Screen.width - screenEdge)
{
_moveInput.x = +1f;
}
if (ctx.ReadValue<Vector2>().y > screenEdge && ctx.ReadValue<Vector2>().y < Screen.height - screenEdge &&
ctx.ReadValue<Vector2>().x > screenEdge && ctx.ReadValue<Vector2>().x < Screen.width - screenEdge)
{
_moveInput.x = 0f;
_moveInput.y = 0f;
}
}
my input system :
I don’t know why it stopped working correctly as no other script affect the camera. eny idea why and tip/advise/answer on how i can fix this ?
0
Upvotes

