How do I create a simple ray?

I have an npc that has a gun and i need a simple ray to shoot in the direction the npc is looking forward? how do I do this?

You would create a new Ray with, NPC.PrimaryPart.CFrame.LookVector), then use either game.Workspace:FindPartOnRay() (docs), or game.Workspace:Raycast() (docs), which both return the first intersecting part, the position of intersection, the material and the surface normal of where the ray intersected the part.

1 Like

It depends looking forward from where? You get the forward direction of anything by using the LookVector of the CFrame then multiply by how far the ray you want to go.