Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how the event : Part.Touched can work with anchored part?

Hello , how can I make a script detect that the pistol bullet (which is anchored) hits a wall? that could solve a lot of problem in my games.

2 answers

You can use raycast that shoots toward the direction the bullet is going, and detect the wall with it

2 comments

0

(i make a vr gun and in vr , we do not use mouse)

0

(Mate i didnt say anything about a mouse, i said make a raycast that shoots toward the direction the bullet is going from the bullet to detect walls)

i found how i can do that :) :

local function ClosestPointOnPart(Part, Point)
--by sircfenner
	local Transform = Part.CFrame:pointToObjectSpace(Point) 
	local HalfSize = Part.Size * 0.5
	return Part.CFrame * Vector3.new( -- Clamp & transform into world space
		math.clamp(Transform.x, -HalfSize.x, HalfSize.x),
		math.clamp(Transform.y, -HalfSize.y, HalfSize.y),
		math.clamp(Transform.z, -HalfSize.z, HalfSize.z)
	)
end

while true do
script.Parent.BulletTouch.Value = false --reset value
local Part1 = workspace.Map
		local Part2 = script.Parent.Parent.Bullet
		local par1 = ClosestPointOnPart(Part1, Part2.Position)
		local par2 = ClosestPointOnPart(Part2, Part1.Position)
		if (math.floor((par1 - par2).Magnitude * 10))/10 < 0.51 then

			script.Parent.BulletTouch.Value = true
		end
wait(0.025)
end

1 comment

0

i don't want to use a ray cause i want to know if the part touch the wall , the ray only work for a bullet

This discussion is preserved as it was. New answers, comments, and votes are closed.