How can I create a raycast like this?

Hi devs,

How could I make a raycast that will create a blood effect from the bullet’s rotation?
That probably doesn’t make much sense, but this might:


This is what I have at the moment (It doesn’t seem to work):

-- script.Parent is the bullet
local ray = Ray.new(script.Parent.Position, script.Parent.CFrame.LookVector * 10)

You need to raycast again destination of the particles. The origin is the bullet’s position, and the direction is the bullet’s lookVector.

Would I multiply the LookVector by something?
It only seems to do anything when I hit the head, and it doesn’t go far.

It is more recommended to use workspace:RayCast() because of the 3rd parameter, RaycastParams.
When you cast a ray and it hit’s a player, generate a raycastparams to ignore the player hit and just go 10 studs ahead or in the range that you specified

--First raycast to detect a player
local FirstCast = workspace:RayCast(origin, direction * range) --use a direction vector with range of one to make it flexible

if FirstCast then
   local HitPos = FirstCast.Position

   local player = --detect if it hit a player or an npc 
   local params = RaycastParams.new()
   params.RaycastFilterType = Enum.RaycastFilterType.Blacklist
   params.FilterDescendantsInstances = {player.Character}

   local secondCast = workspace:RayCast(HitPos, direction * 10, params) --use the same direction from first with new range
   if secondCast then
      local SecondHitPos = secondCast.Position
      ---make a blood effect at the second hit position
   end
end
1 Like