Help with map generation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DiFlector

I’m creating a game like google dinosaur, tell me how to make it so that after CollisionShape2D.is_colliding () becomes false - a new TileMap will spawn from the list at the RayCast2D position?

:bust_in_silhouette: Reply From: Lopy

CollisionShape2D does not seem to have any is_colliding() function, did you mean Area2D.get_overlapping_bodies().size() > 0?

You could do something like this:

var my_area: Area2D
var my_raycast: RayCast2D
var options := [preload("res://..."), ...]

func _ready():
    my_area = $Area #Replace with actual path to the nodes
    my_raycast = $Raycast
    my_area.connect("body_exited", self, "check_count")

func check_count(_body_which_exited):
    if my_area.get_overlapping_bodies().size() > 0:
        var chosen_tilemap := randi() % options.size()
        var new_tilemap: Node2D= options[chosen_tilemap].instance()
        
       #Pick one of the two lines
        new_tilemap.position = my_raycast.position #For the actual raycast's position
       new_tilemap.position = my_raycast.get_collider().position #For the position of what it collides with.
        add_child(new_tilemap)

Edit: wrote my_area.get_overlapping_bodies instead of my_area.get_overlapping_bodies().size().

Ok, I did everything, thank you so much!
It remains only to make the function of deleting Tilemaps that the player has already passed

DiFlector | 2021-02-07 21:50