Some context:
So I'm trying to make a building system equivalent to the one in stardew valley and I'm having a issue with a bug
How i do it:
to find where I'm placing something I use a marker2d with a texture and a area2d with a collision
the code to positioning the marker2d and its children:
func _physics_process(delta):
mouse_pos = get_global_mouse_position()
grid_pos = tilemap.local_to_map(mouse_pos)
snapped_pos = tilemap.map_to_local(grid_pos)
object_placer.global_position = snapped_pos
object_placer_texture.global_position = snapped_pos
after this i run some code that creates a object on the snapped_pos and that code starts like this:
var itemid = Global.current_held_item #is a int
var object = load_item_data(itemid,"object") #is a bool false = item, true = object
if Input.is_action_just_pressed("ui_interact"):
if object == true:
if marker_area.has_overlapping_bodies() == false: #this is where the problem is
#after this is the code that loads and instantiate the scene to make a object
The problem: (attached video should show it)
the problem is that if I move my mouse on top of a existing body (that's what the marker_area checking for) and click interact fast enough it still places a object even though there's a overlapping body but for some reason it doesn't detect it so if you do a frame perfect (I find it quite easy to be honest) button press i can place a object on top of a existing object
what I've tried to fix it:
- I've tried using _process() instead of _physics_process()
- I've tried making a bool variable for whether or not its inside a object and then making that variable update every frame, physics frame, on "func _input(Input):" and on "func _on_area_2d_body_entered()" (and exited)
if anyone know why doesn't detect that its on top of a different body immediately or even better know how to fix it would appreciate the help