i got it sort of working...
how to add a layer mask to the raycastQuery? cause now im also shooting at the player
the reticle screen position seems to be taken from the upper left corner, i cant seem to change this by messing with the GUI
and my decal instantiate code is wrong, im probably doing something wrong with the lookat from position code
const ray_length = 1000
@export var reticle_path: NodePath
@export var impact_normal : PackedScene
@export var force = 20.0
@export var damage = 50.0
@onready var reticle = get_node(reticle_path)
func firebullet():
#it takes the left upper corner point of the reticle?
var screen_pos = reticle.get_global_transform_with_canvas().origin
var camera = self
var from = camera.project_ray_origin(screen_pos)
var to = from + camera.project_ray_normal(screen_pos) * ray_length
var space = get_world_3d().direct_space_state
var phys = PhysicsRayQueryParameters3D.new()
phys.from = from
phys.to = to
var result = space.intersect_ray(phys)
if result:
var collider = result.collider
var n = result.normal
var p = result.position
#print(p)
#print(collider)
#print(n)
#this is a godot4 decal scene>
var impact = impact_normal.instantiate()
collider.add_child(impact)
impact.global_transform.origin = p
impact.look_at_from_position(p, p - n, Vector3.UP)
if collider is RigidDynamicBody3D:
collider.apply_impulse( p - collider.transform.origin , - self.global_transform.basis.z * force)