Trying to create an area that covers the extents of a block mesh, so I can detect mouse clicks on it or other overlapping blocks. The following code is where the area is created. I can't figure out what's wrong with it. There's no errors or warnings, it's just not working as expected.
area = Area.new()
var coll = CollisionShape.new()
var shape = BoxShape.new() # running game with collision shapes
shape.set_extents(half_size) # enabled, shows that this is there
coll.set_shape(shape) # and correctly placed
area.set_translation(half_size) # center of block object
area.connect("area_enter", self, "_on_Area_area_enter") # does nothing
area.connect("input_event", self, "_on_Area_input_event") # does nothing
The signal functions, which end up never getting called:
print("%s entered &s" % [other_area.get_name(), get_name()])
func _on_Area_input_event( camera, event, click_pos, click_normal, shape_idx ):
print("touching block area: %s" % [get_name()])
If it makes any difference, the block is already added as child when this function gets called, but it all happens in the same frame:
var b = pre_block.new( next_block_id(), verts, mesher)
b.init() # create_area_shape() gets called from this one
On further testing I noticed both
area.connect(...) functions return
0, which I think it means no errors (if I connect them more times they return
31 every time except the first).
Also, if I do this right after connecting...
print( area.is_connected( "area_enter", self, "_on_Area_area_enter" ) )
... it returns
So the signals are connected, so I guess the problem may be with the
CollisionShape or the
BoxShape, but I can't figure it out...