I am new to game dev and I’m trying to make a hitscan shotgun for my top down 2d game but all the tutorials I’ve found are either really old or aren’t very applicable. I understand that I need to use raycast2d nodes but I don’t know how to set them up so that they scan the direction and range i want them to.
It’s as easy as setting up your collision layers and running is_colliding() and checking if the return is true or false. If it still doesn’t work and you know when the check is supposed to happen you can force_raycast_update()
Hope you had setup the raycast so add this codes in your player script:
if Input.is_action_just_pressed("shoot"):
#Play sounds & particles...
if $Raycast.is_colliding():
if $Raycast.get_collider().has_method("take_damage"):
$Raycast.get_collider().take_damage(20)
First read the codes to understand, it is important.
Do not forgot to define “take_damage(value)” function in enemy script, and to define “shoot” input map.