Putting a bullet hole where my RayCasts part lands

I want to do it myself because getting stuff handed to you isn’t a good way to learn example; free scripts.

Thats…not really true. An API supplying the normal value for you is not really equivalent to a free script. All the API has done for you is supply you information about the raycast. You still have to know what to do with that information. Don’t be afraid to utilize the API to its fullest extent. You don’t need to do every little tedious task yourself to be a good programmer.

1 Like

Obviously but for me the reason is mostly that the “normal” only goes to the mouse target and I’m using a Velocity to make my bullet drop and the normal doesn’t go to the RayCast part.

You’re going to have some network problems if you’re using velocity to determine where the bullets go. You can use velocity to make the bullet look like it’s falling, but for the actual hit detection please use raycasting.

you’re better off doing something like this:

local start = whatever position you want the ray to start
local lookAt = mousePosition + Vector3.new(0, 5, 0) --this makes your bullet appear as if it is ‘dropping’ 5 studs from the mouse position
local LENGTH_OF_RAY = however long you want your ray to be in studs

local ray = Ray.new(start, (lookAt-start).Unit * LENGTH_OF_RAY)

local part, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, {parts you want to the ray to ignore})

bulletHole.CFrame = CFrame.new(position + normal * how far forward you want the ray to go from the hit position)

if you don’t want to use normal,here is how to do that w/ math: https://www.youtube.com/watch?v=mH9aFGUZdug

local MaxDist = 100

function Fire()
	local Origin = Camera.CFrame.p
	local Direction = Camera.CFrame.LookVector * MaxDist
	
	local rayParams = RaycastParams.new()
	rayParams.IgnoreWater = true
	
	local rayResult = workspace:Raycast(Origin, Direction, rayParams)
	
	if rayResult then
		local hole = Instance.new("Part")
		hole.Size = Vector3.new(1, 1, .1)
		hole.Anchored = true
		hole.CFrame = CFrame.new(rayResult.Position, rayResult.Position + rayResult.Normal)
		
		hole.Parent = workspace
	end
end

Fire()
2 Likes

The normal is based on whatever the raycast hit. It doesn’t “go” anywhere its merely a vector that tells you the orientation of the surface relative to the raycast direction. Even if you want to simulate bullet drop, either way you are gonna need to raycast to the dropped location to know what the bullet hit, so you’ll still have the normal information.

1 Like