Player:
var bullet := preload("res://Scenes/Weapons/Bullet.tscn")
var instance
var player_damage = 10
# Spawn bullet raycast on Mouse1.
if Input.is_action_just_pressed("Action1"):
instance = bullet.instantiate()
instance.damage = player_damage
instance.position = camera.global_position
instance.transform.basis = camera.global_transform.basis
get_parent().add_child(instance)
# Make instance damage, player damage.
instance.damage = player_damage
# Check stuff.
instance.do_thing()
Bullet:
@onready var cast = $RayCast3D
var damage
func do_thing():
if cast.is_colliding():
var collider = cast.get_collider()
if collider is Enemy:
collider.take_damage(damage)
print("Shoot enemy")
if collider is StaticBody3D:
print("Hit wall")
Enemy:
@export var health = 100
func take_damage(damage):
health -= damage
I’m trying to create a system for my 3d shooter where when the player presses the shoot button, the game creates a raycast which then checks if it hits an enemy or wall. And when I shoot it creates the raycast, but when hitting an enemy or wall it prints nothing which means it is not working.