How do I make a camera move according to the cursor?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TherdDev

I want to make a 3D RTS game similar to the Command & Conquer series, but I have no prior game development knowledge and experience.

Right now I’m trying to make the camera move only in the XZ plane when the mouse cursor goes near the edges of the game screen like how panning works in RTS games. I also want to know how to make a game cursor which is only contained within the window of the game such that it collides with the window’s edges.

:bust_in_silhouette: Reply From: Wakatta

Well look at you bitting off more than you can chew.
Guess I’ll lend you a knife.

extends Camera

var last_position = Vector2()
var velocity = Vector2()
var speed = 0.2

func _input(event):
    if event is InputEventMouseButton:
        if event.pressed:
            last_position = event.position
        else:
            velocity = Vector2.ZERO
    elif event is InputEventMouseMotion:
        velocity = (event.position - last_position) * speed
        translate(Vector3(-velocity.x, 0, -velocity.y)
        last_position = event.position

For the second part of your question use clamp with the viewport rect or set a custom cursor. Won’t spoon feed you anymore than that.