How to make a ball that bounces X times and disapper?

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

I really don’t know if i need to use a timer or other type of node…

:bust_in_silhouette: Reply From: kidscancode

If you’re using a KinematicBody2D, you can increment a variable every time the body bounces. I don’t know how you have your movement set up, but with move_and_collide() this is pretty straightforward:

var bounce_count = 0

func _physics_process(delta):
    var collision = move_and_collide(velocity * delta)
    if collision:
        velocity = velocity.bounce(collision.normal)
        bounce_count += 1
    if bounce_count >= 3:
        queue_free()
    

Thanks! I think that is what i needed…

StrikerSVX | 2018-09-04 22:42