Smaller, smoother spray circles

This commit is contained in:
Rob Kelly 2025-03-01 16:59:39 -07:00
parent 0fee0a155f
commit c753aa68c9
3 changed files with 18 additions and 16 deletions

View File

@ -15,6 +15,7 @@ var gravity: Vector3 = (
)
@onready var camera_pivot: Node3D = %CameraPivot
@onready var spray_muzzle: Marker3D = %SprayMuzzle
@onready var spray_effect: MeshInstance3D = %SprayEffect
@ -38,9 +39,10 @@ func fire_spray() -> void:
if raycast.is_colliding():
var collider := raycast.get_collider()
if collider is GunkBody:
(collider as GunkBody).paint_mask(
raycast.get_collision_point(), raycast.get_collision_normal(), SPRAY_RADIUS
)
# Adjust radius to compensate for distance from muzzle
var point := raycast.get_collision_point()
var radius := sqrt(point.distance_to(spray_muzzle.global_position)) * SPRAY_RADIUS
(collider as GunkBody).paint_mask(point, raycast.get_collision_normal(), radius)
func _physics_process(delta: float) -> void:

View File

@ -14,7 +14,7 @@ albedo_color = Color(0, 1, 0.301961, 0.254902)
[sub_resource type="PrismMesh" id="PrismMesh_ow0jh"]
material = SubResource("StandardMaterial3D_ng43h")
size = Vector3(1, 2, 0.1)
size = Vector3(0.5, 2, 0.1)
[sub_resource type="QuadMesh" id="QuadMesh_cn0yq"]
size = Vector2(1, 0.05)
@ -35,29 +35,27 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, -0.1, -0.1)
mesh = SubResource("BoxMesh_ua7a2")
[node name="SprayMuzzle" type="Marker3D" parent="CameraPivot/SprayNozzle"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15)
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.997564, -0.0697565, 0, 0.0697565, 0.997564, 0, 0, -0.15)
[node name="RayCast3D" type="RayCast3D" parent="CameraPivot/SprayNozzle/SprayMuzzle" groups=["SprayCast"]]
enabled = false
target_position = Vector3(-0.4, 0.1, -2)
target_position = Vector3(-0.2, 0, -2)
[node name="RayCast3D2" type="RayCast3D" parent="CameraPivot/SprayNozzle/SprayMuzzle" groups=["SprayCast"]]
target_position = Vector3(-0.2, 0.1, -2)
target_position = Vector3(-0.1, 0, -2)
[node name="RayCast3D3" type="RayCast3D" parent="CameraPivot/SprayNozzle/SprayMuzzle" groups=["SprayCast"]]
target_position = Vector3(0, 0.1, -2)
target_position = Vector3(0, 0, -2)
[node name="RayCast3D4" type="RayCast3D" parent="CameraPivot/SprayNozzle/SprayMuzzle" groups=["SprayCast"]]
target_position = Vector3(0.2, 0.1, -2)
target_position = Vector3(0.1, 0, -2)
[node name="RayCast3D5" type="RayCast3D" parent="CameraPivot/SprayNozzle/SprayMuzzle" groups=["SprayCast"]]
enabled = false
target_position = Vector3(0.4, 0.1, -2)
target_position = Vector3(0.2, 0, -2)
[node name="SprayEffect" type="MeshInstance3D" parent="CameraPivot/SprayNozzle/SprayMuzzle"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, -0.0697565, -0.997564, 0, 0.997564, -0.0697565, 0, 0.0436133, -1)
visible = false
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, -1)
mesh = SubResource("PrismMesh_ow0jh")
skeleton = NodePath("../../..")

View File

@ -71,7 +71,7 @@ func _get_uv(point: Vector3, normal: Vector3) -> Vector2:
return (uv1 * bc.x) + (uv2 * bc.y) + (uv3 * bc.z)
## Paint a rectangle on the mask at a given point & normal on the mesh.
## Paint a circle on the mask at a given point & normal on the mesh.
func paint_mask(point: Vector3, normal: Vector3, radius: int) -> void:
var local_point := point * global_transform
var local_normal := normal * global_basis
@ -79,4 +79,6 @@ func paint_mask(point: Vector3, normal: Vector3, radius: int) -> void:
if uv == Vector2.INF:
return
var px_center: Vector2 = uv * mask_control.size
mask_control.queue_draw(func() -> void: mask_control.draw_circle(px_center, radius, MASK_COLOR))
mask_control.queue_draw(
func() -> void: mask_control.draw_circle(px_center, radius, MASK_COLOR, true, -1, true)
)