Area2d that bounces off walls

Godot Version

Godot v4.2.1

Question

As title says I have a very silly issue, I just cant figure out right now and the worst part is, its very much my own fault.

I have a racing game, where you drive a car and have a turret on the back where you can shoot, you can also collect different turrets, such as rocket launchers to fire different types of projectiles. an issue I had early on was when the projectile would be spawned by a player or ai, it would hit the original spawner, obviously I didn’t want this, so I changed the projectile to an area2D instead of one of the body nodes that way I dont have to worry about it colliding and can just set the original owner of the body when it spawns and if it detects that its colliding with the owner to ignore it.

Issue:

I had a fun idea for a projectile where it would bounce off of walls and cars for a certain amount of hits, this is an extract of my code, shortened as every projectile shares the same gd file, so theres a lot unused such as spawning an explosion

@export var damage = 1
@export var speed = 2000
@export var health = 1

@export var bounces = 0

@onready var direction = transform.x

func  _process(delta):
  position += direction * speed * delta

func Hit(body):
  if body == origin: return
  if "origin" in body:
  if body.origin == origin: return
  if body.is_in_group("NotProjectile"): return
  if body.is_in_group("Hittable"):
  if !body.has_method("TakeDamage"): body.get_node("CarManager").TakeDamage(damage)
  else: body.TakeDamage(damage)

  if bounces > 0:
    var collisionNormal =  (global_position - body.global_position).normalized()
    direction = direction.bounce(collisionNormal)
    bounces -= 1
    return

  queue_free()

the issue is my projectile goes through walls, obviously because its an area2D, what I should really do, is make them all static bodies and use collision masks / layers to make it so my projectile doesn’t collide with its original car, however I was wondering if there was away I could not do that (like I said earlier very silly) some way where I could make the projectile not go through walls as an area.

thank you for any help!

Well you probably could hack something together, yes, but there’s really no reason why you would do that when there’s a built-in node that does it for free.

Yeah I just redid my projectile system yesterday, since there wasnt much that actually needed changing, I just wanted to see if there was a way I could be lazy. Thank you for your advice!

Idea: you can use two scenes for the bullets.
At first you start with your lazy area2d nodes and then when they have traveled a bit or are about to hit a wall exchange them with proper physics nodes in the second scene.

Well, you already redid it but I figured I’d share.

I think you should actually be able to use RigidBody2D if you just set the collision layers such that player projectiles only collide with enemies and vice versa.