How to use overlaps_body ( Node body )?

BangelBangel Posts: 1Member
edited March 24 in 2D

I want to detect if my character touch the bottom of a block with the top of his head when he is jumping, and change his y velocity if it is the case. I tried to use signal with Area2Dbut that only worked in some occasions, and I think the overlaps_body func is the key of my problem. I tried to use it like this :

func _physics_process(delta):
    if $Area2D.overlaps_body("TileMap"):    #doesn't work anymore with simply  (TileMap)
        velocity.y = 0

But that didn't worked very well :/
So, how to use it?


  • MegalomaniakMegalomaniak Posts: 2,028Admin

    Might the tilemap have it's name changed? Check the remotes in the editor while running the game.

  • TwistedTwiglegTwistedTwigleg Posts: 2,128Admin

    Based on what I have read from the documentation on the function, you need to pass a reference to the Tilemap node itself to the overlaps_body function.

    I have not tested, but I think something like this may work:

    var tilemap_node = null
    var area_node = null
    func _ready():
        area_node = $Area2D
        tilemap_node = $Tilemap
    func _physics_process(delta):
        if area_node.overlaps_body(tilemap_node):
            velocity.y = 0

    Also, welcome to the forums! :smile:

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file