How to make part rotate according to ray hit part

I’m trying to make bullet holes, how do I make it so the bullet holes orientation is correct?

You can use the third returned value of FindPartOnRay, the normal. Then, construct a CFrame with the returned normal as the lookVector, and voila.

Example: CFrame.new(SecondReturnedValueHitPosition, SecondReturnedValueHitPosition + ThirdReturnedValueNormal)

You gotta use FindPartOnRay and normals

local Hit, Pos, Normal = workspace:FindPartOnRay(ray)

then check if hit.Parent doesn’t have a humanoid, so bullet holes won’t be on the player

Now you make a bullet hole and decal

local BulletHole = Instance.new("Part")
BulletHole.Size = Vector3.new(0.65, 0.65, 0.2)

local Decal = Instance.new("Decal")
Decal.Parent = BulletHole
Decal.Face = Enum.NormalId.Front
Decal.Texture = "rbxassetid://ID"

Calculate new position for the BulletHole

local NewPos = CFrame.new(Pos, Pos + Normal)

Set BulletHole cframe

BulletHole.CFrame = NewPos * CFrame.Angles(0,0, math.random(0,360))

and weld BulletHole to the wall

local Weld = Instance.new("Weld")
Weld.Part0 = Hit
Weld.Part1 = BulletHole
Weld.C0 = Hit.CFrame:ToObjectSpace(NewPos * CFrame.Angles(0, 0, math.random(0, 360)))
Weld.Parent = BulletHole

There you go!

image

10 Likes