Making bullet holes using RaycastResult.Normal?

So I’m giving a try at making a raycasting gun. I know that RaycastResult.Position returns the position and you can position the parts that way. But it doesn’t rotate, for example if you shot at a rotated wall, the bullet hole would not be on the wall it would be in the wrong rotation. Now, there’s a property called RaycastResult.Normal. It returns the face Vector3 that the raycast hit on. So my question is, how can I rotate my bullet hole using this property? My current script if you need it:

Result: The RaycastResult
BulletHole: The cloned Hole

if Result then
      local Position = Result.Position
      local BulletHole = Assets:WaitForChild("BulletHole"):Clone()
      BulletHole.Parent = GunParts
      BulletHole.Position = Position
      Debris:AddItem(BulletHole, 5)
end
4 Likes

people often just change the cframe of the bullet hole to what I put below.

CFrame.new(position, position + normal)
4 Likes

image

Try subtracting instead;

CFrame.LookAt(position, position - normal)

The decal should be placed on the front side of the bullet part.

3 Likes

Thanks dude! I had it on Top
image
I used CFrame.lookAt(Hit,Hit + Normal)

2 Likes

what does the “normal” stands for can you explain ?

it seems like I made somethings work but now it positions it self down on the Y axis like -500

local Hit = workspace:Raycast(Bullet.Position, Bullet.CFrame.LookVector * BulletVelocity * 1.5)
		if Hit then
			if Hit.Instance.Parent:FindFirstChild("Humanoid") and DamageEvent ~= nil and Hit.Instance.Parent.Name ~= player.Name then
				if sentByOrigin ~= false then
					--print(Hit.Instance, Hit.Instance.Parent)
					DamageEvent:FireServer(Hit.Instance.Parent, BulletDamage)
				end
				Loop:Disconnect()
				Bullet:Destroy()
			else
				print(Bullet.Position)
				local hitEffect,bulletHole = Instance.new("Part"),Instance.new("Part")
				hitEffect.Position = Bullet.Position
				script.Spark:Clone().Parent = hitEffect
				hitEffect.Anchored = true
				hitEffect.CanCollide = false
				hitEffect.Transparency = 1
				
				bulletHole.Name = "BulletHole"
				gunConfig.bulletHole:Clone().Parent = bulletHole
				bulletHole.Transparency = 1
				bulletHole.CanCollide = false
				bulletHole.Size = Vector3.new(0.2, 0.2, 0.01)
				bulletHole.CFrame = CFrame.new(Hit.Position, Hit.Normal) -- THIS PART
				
				bulletHole.Parent = game.Workspace
				hitEffect.Parent = game.Workspace
				
				Loop:Disconnect()
				Bullet:Destroy()
				wait(0.1)
				hitEffect:Destroy()
			end
		end
		Bullet.CFrame *= CFrame.new(0, 0, -BulletVelocity * (deltaTime * 20))
1 Like

This was already solved, but the normal is the Vector3 direction facing outwards on the part you hit.
image
The normals are shown by the arrows in the diagram.
Also you said you used CFrame.lookAt(), which is fine, but there is a function CFrame.lookAlong() for exactly what you want.

Ohhh ok this explains better thanks for the info :slight_smile: