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

How to check if a part touched a model?

Asked by
Xyternal 247 Moderation Voter
2 years ago

So I have a cannonball, and I want to see if it touched a MODEL not a part. But I didn't know where to start, so I thought I would come here. I want it to see if the ball touches the model, and if it touched a model, then you get a point, with a debounce, of course. But I think I can take care of that. For now, can you please help me find witch model, not part, my ball touched?

3 answers

Log in to vote
1
Answered by 2 years ago

You have a few options here...

1 is an ugly method called magnitude, works best on circles:

if (part.Position-part2.Position).Magnitude < (whatever the size of part2 is, any axis) then
    print('in range')
end

You can loop it or whatever.

You can use region3, raycasting, .Touched, GetTouchingParts()

local part = workspace.Part
for _, v in pairs(part:GetTouchingParts()) do
    print(v.Name)
end

You can loop it again for the next time its touched

then theres the good old .Touched

part.Touched:Connect(function(obj)
    if obj:IsDescendantOf(workspace.Model) then
        print('model touched')
    end
end)

You can also do it the other way

for _, v in pairs(model:GetDescendants()) do
    v.Touched:Connect(function(obj)
        if obj == part then
            print('touched part')
        end
    end)
end

So uh, see which one helps you, gl bye

0
bye Xyternal 247 — 2y
0
bye greatneil80 2647 — 2y
0
bye Xapelize 2658 — 2y
0
magnitude is a good choice for squares hitbox, get touching part is useless tbh, 3rd is just check parent and 4th is the best imo, but if you dont want to index anything then my method i guess Xapelize 2658 — 2y
View all comments (5 more)
0
Your method is good on performance, magnitude is terrible for square hitboxes. GetTouchingParts is extremely useful, I don't know why you think it's useless, I'd find other ways, methods and other resources though. You could also apply heavy math but that's absurd greatneil80 2647 — 2y
0
Wait that's not even your method, that's Frindows im talking about. Your method is absolutely useless, sorry greatneil80 2647 — 2y
0
Your 3rd script was exactly what I wanted. thanks Xyternal 247 — 2y
0
I was looking for a way without a loop, and I found it. Xapelize had a good answer, but like.... Xyternal 247 — 2y
0
you mean frindow? xapelizes answer was bad greatneil80 2647 — 2y
Ad
Log in to vote
1
Answered by 2 years ago

It is currently not possible to detect if it is touching an entire model but instead you can insert a part into the model and resize it until it is even with the model. Then you can set CanCollide to false and set Transparency to 1.

0
Thats actually a good idea. I didn't know though, that you couldn't find a model. One bad thing though, my model is a boat Xyternal 247 — 2y
0
with a bow and all Xyternal 247 — 2y
0
Just weld the part to the boat NotFrindow 346 — 2y
0
alright Xyternal 247 — 2y
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

Just detect hits between parts, and detect if its in your desired model. Very simple solution:

if hit.Parent:IsA("Model") and hit.Parent.Name == "YourModel" then

0
I thought that only worked for parts Xyternal 247 — 2y
0
it only works for baseparts, or unions, but you could detect parent Xapelize 2658 — 2y
0
mate, your answer didn't work XD Xyternal 247 — 2y

Answer this question