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!