0 votes

Hi, i want a camera movement like clash of clans or hay day but with mouse.
So zoom in and out and move left and right.

in Engine by (86 points)

1 Answer

0 votes

Apologies for the lack of comments feel free to ask about any enigmas you face

extends Camera2D
var touch = false
var mouse_pos = Vector2()
export var zoom_speed = 1.2

func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_WHEEL_UP:
            zoom /= event.factor * zoom_speed
        elif event.button_index == BUTTON_WHEEL_DOWN:
            zoom *= event.factor * zoom_speed
        elif event.button_index == BUTTON_LEFT:
            if event.is_pressed():
                touch = true
                mouse_pos = event.position
            else:
                touch = false

    elif event is InputEventMouseMotion and touch:
        var kiariCephus = mouse_pos - event.position
        translate(kiariCephus)
        mouse_pos = event.position
by (4,638 points)

Thank you :) its working!!! THANKS

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 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 webmaster@godotengine.org with your username.