Sorry if this question is too noobie, but I've been scratching my head for hours and can not find a solution.
I have a player that shoots bullets. The bullets are RigidBody2D and are shooted with the left button of the mouse. The fire rate is 0.2.
I have some trees that are RigidBody2D.
I use the "body_entered(body)" signal in the bullet to watch for collisions. When I detect one, I play an explosion and delete the bullet ("queue_free").
I use the "body_entered(body)" signal in the trees to see what hit it. If it's a bullet, it takes damage. If the damage is enough, it's eliminated ("queue_free").
The player need three hits to kill the tree.
If the player is very near the tree, everything works as expected: the three bullets detect the collsion, the three explosion animations are played and the bullets dissapear. The tree detects the hits, it's life goes down and with the third hit, dies and dissappears.
But if the player is far from the trees, things go wrong. The bullets detect the tree, the explosions are played and the bullet dissapear, but the tree detects far less collisions than bullets shot. The tree detection rate goes down with the distance. If the player is on the opposite corner of the tree, the tree detects only one bullet from 8 or 9 shooted.
If the fire rate is higher (ie. 0.01), the problem is way more visible, with hundreds of shoots for every collision.
I have "Contact Monitor" ON and "Contacts Reported" on 100 for the bullets and the trees.
Any ideas?
it's frame rate related? Shouldn't I be using signals?
This are the trees (arboludo):
extends RigidBody2D
onready var vida = 30
func _on_arboludo_body_entered(body):
if body.name == "bullet":
vida -=10
$health_label.text = str(vida)
if vida <= 0:
queue_free()`
This are the bullets (bullet):
extends RigidBody2D
var impacto = preload("res://impacto.tscn")
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
func _on_bullet_body_entered(body):
if !body.is_in_group("player") and !body.is_in_group("bullets"):
var impacto_instance = impacto.instance()
impacto_instance.position = get_global_position()
get_tree().get_root().add_child(impacto_instance)
queue_free()
I have this vid with were you can see the problem. In the debugger window you can see that only three shots are needed for the first tree, but for the second you have to shoot way more. The bullets act as expected, but the tree did not react to most of the bullets.
Here
I'm using v3.5.1.stable.official [6fed1ffa3]