Godot Version
4.7.1.stable
Question
Hello! I am relatively new to programming, and Gdscript as a whole.
I am trying to code a function which looks for the bodies that it is overlapping, and then shrinks to fit about halfway inside that area. This is to avoid picking up an object behind an object above it.
I’ve tried a couple methods already, but none of them seem to work as intended, including have a variable “set_size” that is added and subtracted when entered and exited respectively. It doesn’t work as intended obviously.
Embarrassed to admit, but I’ve been banging my head on this for a bit. Help is appreciated.
ref
var current_coin: RigidBody2D = null
var set_size = 0.05
func _on_interacting_component_body_entered(body: RigidBody2D) -> void:
# if intersecting with a body, change interacting_component's y scale, so that it only intersects the bottom coin
if body:
interaction_cast.scale.y -= set_size
if current_coin == null:
if body.is_in_group("pickable"):
current_coin = body
func _on_interacting_component_body_exited(body: Node2D) -> void:
# when no longer intersecting with a body, revert back to longest range
if body:
interaction_cast.scale.y += 0.05
if current_coin == body:
if current_coin.freeze == false:
current_coin = null