Invalid call. Nonexistent function 'bounce' in base 'TileMap'.

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

This is my code

func _on_top_checker_body_entered(body):
$AnimatedSprite.play(“squashed”)
speed = 0
set_collision_layer_bit(4,false)
set_collision_mask_bit(0,false)
$top_checker.set_collision_layer_bit(4,false)
$top_checker.set_collision_mask_bit(0,false)
$sides_checker.set_collision_layer_bit(4,false)
$sides_checker.set_collision_mask_bit(0,false)
$Timer.start()
body.bounce()
$SoundSquash.play()

so its about body.bounce()

What do I do?

:bust_in_silhouette: Reply From: timothybrentwood

What’s going on is the body object is a TileMap object. TileMap objects do not have a bounce() function declared in their class so it crashes.
The quick and dirty solution is:

func _on_top_checker_body_entered(body):
    if body.has_method("bounce"):
        $AnimatedSprite.play("squashed")
        speed = 0
        setcollisionlayerbit(4,false)
        setcollisionmaskbit(0,false)
        $topchecker.setcollisionlayerbit(4,false)
        $topchecker.setcollisionmaskbit(0,false)
        $sideschecker.setcollisionlayerbit(4,false)
        $sideschecker.setcollisionmask_bit(0,false)
        $Timer.start()
        body.bounce()
        $SoundSquash.play()

To give you a more accurate solution I would need to know what object you want to bounce(). Do you want to bounce() the parent object of your topchecker object? If so change body.bounce() to get_parent().bounce().

That is part of my enemie script and its supposed to make my Player bounce. When I # the line I just hit the enemie without bouncing. I tried “get_parent().bounce()” and it didn’t work.

Update: i copied your code and modified it a bit and it works thank you so much!!

Tjoeser | 2021-06-13 21:31