0 votes

I am starting to make an isometric grid based game. Got a coursor scene wich follows the mouse, selects tiles, and tells the game the cell where it is hovering. Normally, i have the real mouse hidden. Works perfectly, but when using a camera, for every pixel that the top-left corner of the camera is away from origin (either by its position or its offset), there is a displacement between the real mouse and the coursor scene one. The coursor one, stil reads the tiles correctly, but sometimes i cant even bring it into what i am viewing, because of the displacement. Question is, what is happening? and besides what is happening, does anybody have a solution?

this is the code of the coursor

class_name Cursor
extends Node2D

signal left_click(cell)
signal moved(new_cell)

onready var grid: Resource = preload("res://Source/System/Grid.tres")

var cell := Vector2.ZERO setget set_cell

func _unhandled_input(event: InputEvent) -> void:
    if event is InputEventMouseMotion:
        cell = grid.pixel_to_cell(event.position)
        self.position = event.position
    elif event.is_action_pressed("left_click"):
        emit_signal("left_click", cell)
        get_tree().set_input_as_handled()

func set_cell(value: Vector2) -> void:
    cell = value
    emit_signal("moved", cell)

the only relevant part would be

if event is InputEventMouseMotion:
     self.position = event.position

Camera2d and Coursor are silbing nodes, so ones position shuldnt affect the other.

Godot version v 3.3
in Engine by (30 points)

Please log in or register to answer this question.

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.