Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
gs_115 11
4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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

0
(i make a vr gun and in vr , we do not use mouse) gs_115 11 — 4y
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) Azure_Kite 885 — 4y
Ad
Log in to vote
-3
Answered by
gs_115 11
4 years ago

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
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 gs_115 11 — 4y

Answer this question