Godot Version
4.6.2.stable
Question
So I have a card that moves when you click and drag it, and a TextureButton that changes the texture when pressed(no other mechanic). I have trouble trying to prioritize moving the card than pressing the button when they are overlapped. I don’t know what is the issue. I can press the button and drag the card, but i can’t drag the card and not press the button.
In the tree, the button is on top and then the card. The card has a process priority of 0, and button process priority is 5. Button Control Mouse is Pass.
Here is the code of the card, but I think it doesn’t do much:
extends Node2D
# Variables
var selected = false
var mouse_offset = Vector2(0, 0)
var speed = 400
var tilt_amount = 0.01 # Maximum tilt in radians
var tilt_speed = 10.0
var direction = 0
signal relativo(relative:float)
func _physics_process(delta):
# Tilting: -direction tilts right when moving left, left when moving right
var target_tilt = -direction * tilt_amount
# Using lerp_angle to smoothly rotate
if selected:
if direction != 0:
rotation = lerp_angle(rotation, target_tilt, tilt_speed * delta)
elif direction == 0:
rotation = lerp_angle(rotation, 0, tilt_speed * delta)
else:
rotation = lerp_angle(rotation, 0, tilt_speed * delta)
# Called when the node enters the scene tree for the first time.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if selected:
followMouse()
func followMouse():
position = get_global_mouse_position() + mouse_offset
func _input(event):
if event is InputEventMouseMotion:
# Using lerp_angle to smoothly rotate
if !event.relative.is_zero_approx():
direction = -event.relative.x
else:
direction = 0
func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.is_pressed():
mouse_offset = position - get_global_mouse_position()
selected = true
else:
selected = false
print("Soy una carta")
get_viewport().set_input_as_handled()
Thank you for reading, hope you can help me.