Gun Decal Rotation Issue. ): my barin is to dumb to code

Godot Version



I’m trying to create a gun that, when it shoots a ray and hits an object, it leaves a mark on that object. However, I’m having trouble figuring out how to make the mark face the right direction upon impact.


can any one help here is my code

extends RayCast3D
const RAY_LENGTH = 1000.0

func _input(event):
	if event is InputEventMouseButton and event.pressed and event.button_index == 1:
		var space_state = get_world_3d().direct_space_state
		var cam = $/root/Node3D/Character/Head/Camera
		var mousepos = get_viewport().get_mouse_position()
		var origin = cam.project_ray_origin(mousepos)
		var end = origin + cam.project_ray_normal(mousepos) * RAY_LENGTH
		var query = PhysicsRayQueryParameters3D.create(origin, end)
		query.collide_with_areas = true
		var result = space_state.intersect_ray(query)
		target_position = end
		if result:
			var collider = result.collider
			var decal =
			var p = result.position
			var sample = $/root/Node3D/CSGBox3D8/Decal
			decal.position = p
			decal.size = sample.size
			decal.texture_albedo = sample.texture_albedo

you can use look_at() to make the decal look at the camera or the normalized collision