#area2Ds behaving strangely when scaling them.

4 messages · Page 1 of 1 (latest)

honest osprey
#

Up front, this is godot 4.0

I'm making a turn based game where an area2d is attached to each actor. The area2D starts off with visible = false and a signal for an input_event attached to the main script. When the user presses a move button, the signal on the button scales the area2d based on their stats, and it's supposed to represent the area in which the player can click to move the character to.

At first, it didn't work at all. I had a few if checks in the signal for clicking on it and print() in the final one to show me it was working. I never saw anything, so I put a print outside of any if checks, and still got nothing. I turned on visible collision shapes to make sure it was scaling correctly, and it definitely is. Then I noticed something strange. It is triggering the input_event signal, but only in very specific regions of the area2d shape

The area that actually works of the collision shape is the image with the green circle and red lines outlining where the mouse is actually triggering the signal.

I tried changing how the area2D got scaled. Only scaling the root node, or only changing the radius value on the circle shape. It appears to behave the same.

If i don't set the area2d.visible = false, then it works as expected, up until the function runs that scales it.

Is this a bug? Am I missing something obvious? I'm really stumped with this.

#

Here's the code I'm using, I'll try to commentate it for better context: ```CC
func _on_move_button_pressed(): #this is the signal connecting from the area2d to the script of the parent object to the actor packed scene. These actors get instantiated in a loop when the combat loads.
CombatUIContainer.visible = false #this hides the UI element that the player just clicked on to choose the move button.
current_creature.refnode.visible = true #this is a graphical effect that uses the _draw function to draw a reticle visible to the player that scales with the area2D that they can move within
current_creature.refnode.drawing = true #this makes the _draw() circle pulse in an aethetically pleasing way
current_creature.move_area.visible = true # this is what makes the area2D the player can move in become visible to the engine, so that it can be clicked on
current_creature.move_area_shape.shape.radius = current_creature.move_distance # this scales radius of hte circle collision shape to be inline with the user's stats and the graphical effect

#and current_creature is a variable assigned when the game decides the current creature's turn. It's a variable that refers to a child in a $ style.
print("Move Button Pressed")```

#

I've fiddled around with a couple things, namely how the scaling happens, and now it doesn't work in any part of the shape2d?

#

Actaully I just noticed that it's scaling the shape2d for every creature? Shouldn't that not be the case since the current_creature.move_area_shape.shape.radius is only one child? Why would that affect every child?