Spawn blood decals on walls if player is close enough?

I made a simple script to spawn blood decals on the floor if the player takes enough damage, or dies. But I am wondering how I’d go about updating this script so if the player is near a wall, it’ll spawn some decals on the wall too. Here’s an image of what it looks like right now.
blood
Since I am right next to a wall when dying I’d want some decals to appear on the wall too.
Any ideas?

I don’t know if this is the ideal way to go about it but I would use 4 different ray-casts from the player’s head to check if it hits a wall on the X/Z plane.
4 different directions should be accurate enough to find the wall.

Once the ray hits a wall, you could then create an invisible part with your texture on it, where its rotation matches the walls (and is oriented to face the body)

This is a fairly simple method :

splat_texture = Instance.new("Decal");
splat_texture.Texture = "..." -- insert your splat texture

function check_wall(hit, position, dir)
  if not hit then return end
  if (hit.Name == "Wall") then -- tell it what to find
    local part = Instance.new("Part", workspace)
    part.Anchored = true
    part.Transparency = 1
    part.Rotation = hit.Rotation;
    part.CFrame = CFrame.new(position);
    
    if dir == 1 or dir == 2 then
      part.Size = Vector3.new(1,6,6); -- X orientation
    elseif dir == 3 or dir == 4 then
      part.Size = Vector3.new(6,6,1); -- Z orientation
    end
    
    local texture;
    texture = splat_texture:Clone();
    texture.Parent = part
    texture.Face = "Front"
    texture = splat_texture:Clone();
    texture.Parent = part
    texture.Face = "Back"
    texture = splat_texture:Clone();
    texture.Parent = part
    texture.Face = "Left"
    texture = splat_texture:Clone();
    texture.Parent = part
    texture.Face = "Right"
  end
end

function splat_walls(player)
  local head = player.Character.Head;
  local ray1 = Ray.new(head.Position, Vector3.new(-5, 0, 0)); // left
  local ray2 = Ray.new(head.Position, Vector3.new(5, 0, 0)); // right
  local ray3 = Ray.new(head.Position, Vector3.new(0, 0, -5)); // back
  local ray4 = Ray.new(head.Position, Vector3.new(0, 0, 5)); // front
  
  local hit, position, normal;
  local ignore = player.Character;
  hit, position, normal = Workspace:FindPartOnRay(ray1, ignore);
  check_wall(hit, position, 1);
  
  hit, position, normal = Workspace:FindPartOnRay(ray2, ignore);
  check_wall(hit, position, 2);

  hit, position, normal = Workspace:FindPartOnRay(ray3, ignore);
  check_wall(hit, position, 3);

  hit, position, normal = Workspace:FindPartOnRay(ray4, ignore);
  check_wall(hit, position, 4);
end

-- Simply call splat_walls(player) when player's character dies
5 Likes