0 votes

so i was making my first fps game . after coding the bullets and testing it the fist bullet always collide but then it rarely collide

https://imgur.com/a/ZyO7v1K

the ennemies(kinematicbody) works fine in calculating the score so i guess the problem is with the bullets code

extends Area
var speed = 100
var velocity = Vector3()
onready var timer = get_node("Timer")
func start(xform):
     transform = xform
 velocity = + transform.basis.x * speed

func _process(delta):
  transform.origin += velocity * delta

func _on_Bullets_body_entered(body):
   if body.get_name() == "Ennemy1":
        body.queue_free()

func _on_Timer_timeout():
     self.queue_free()  
in Engine by (20 points)

do the bullets realy intersect the boxes? or are they "jumping" through the boxes because of their speed?

yea they interact with some

1 Answer

0 votes
Best answer
func _on_Bullets_body_entered(body):
   if body.get_name() == "Ennemy1":
        body.queue_free()

All your enemies haven't the same name in the node tree, so

body.get_name() == "Ennemy1":

will return true with the first Ennemy1 instantiate but will return false with the others ( their name will be increment by one),

. You should change your condition.

For example you could use groups.
https://docs.godotengine.org/fr/stable/getting_started/step_by_step/scripting_continued.html#groups

by (288 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.