In first basic levels are only balls, with diameter 0.4m, so Collector(Area3D) could be placed with collider below surface 0.8m and safely remove them.
But what about different shapes such as Prism, Cone, etc. which could be falling a different directions or might have not typical lengths ?
Should I make for each type of object different Collector(Area3D) to only detect body_enter signal at certain height, or there is some different solution to this problem?
How to make sure to player gets points and object is removed after complete disappear from scene? ( if I get player points before is certain the object falls it might glitch it.
Instead of removing the object when it enters the hole, I would Place an area at ground Level and remove (and score) any objects that exit it with downward velocity. This way, the height basically doesn’t matter
Assuming that object’s position roughly coincides with its collider center, you can just check if the position is below some vertical coordinate (which is slightly below ground). If that’s the case the object is pretty much guaranteed to fall down the hole. Check only for objects that entered the vicinity of the hole, of course.
Alternatively, if you want to avoid manual checking in script, put a tiny area at the center of each object and detect its entrance by some area down in the hole.
current code attached to Area3D which is responsible of detecting bodies falling below ground.
would I need to get from this script ( GameSystem_Level1) parent of this Area3D and check and remove based on it? - or need to transfer logic to objects itself to emit signals?
func _on_collector_body_entered(body: Node3D) -> void:
if body.is_in_group("ball"):
balls_to_collect -= 1
counter.text = "Left to collect: " +str(balls_to_collect)
if balls_to_collect <= 0 and not game_won:
game_won = true
win_game()
level_1.stop_level()
await get_tree().create_timer(3.0).timeout
get_tree().call_deferred("change_scene_to_file", "uid://c030bssualgeh")
if body.is_in_group("fallable"):
score += body.value_of_object
xp_bar_calc()
check_score()
body.queue_free()
func _on_collector_area_entered(area: Area3D) -> void:
pass # Replace with function body.
Scene Tree of Level - Gamesystem have basic script plus for each level extend.