0 votes

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.

Godot version 3.5
in Engine by (12 points)

1 Answer

0 votes

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
            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.

by (5,204 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.