Hey @Schuster!
I made some changes and added some comments explaining what I changed. Hopefully it helps :smile:
func shoot(delta):
var collider
if Input.is_action_just_pressed("shoot"):
ray_projectile.set_cast_to(Vector3(0, 0, -150))
# While this is not necessarily needed, it is probably a good idea to force
# the raycast to update before checking if it has collided.
# (you may only need this If ray_projectile.enabled is false)
ray_projectile.force_raycast_update()
if ray_projectile.is_colliding():
collider = ray_projectile.get_collider()
var hit_new = hit.instance() #sparks particle
# Side note: If you add the particles as a child of the collider, when the collider moves so will
# the particles. It is not per say an issue, but it is something to keep in mind :)
collider.add_child(hit_new)
# Because we have updated and changed the raycast's properties, we'll need to get
# the position of the raycast collision here if we want to have the most up to date
# collision position.
# Also, get_collision_point returns the position of the raycast collision in global space, so
# we'll use it to set the global position of the sparks.
var point = ray_projectile.get_collision_point()
# Set the position of the particles to the position of the raycast collision
hit_new.global_transform.origin = point
print(collider)
Side note: I'm super happy that the FPS tutorial has helped! It is always cool seeing that it has helped someone, as when you are writing tutorials you really have no idea whether it will be helpful or not.
I'm glad the tutorial has been helpful, and I hope your FPS template goes well! :smile: