Hello! so im trying to find a better way to detect when something gets hit by a wall.
Im making a destructible sphere using fragments so I used a touch event and velocity detection but when another part is falling below it, the velocity is high and it got touched, the sphere breaking func already starts as opposed to real life were a rock and another rock below it are falling at the same, they wont break unless it hits a floor or a wall. freely reply if you dont get it haha
Maybe you can check if the part that it touched was a wall?
local walls = {}
ball.Touched:Connect(function(p)
if p and walls[p] then
-- code here
end
end)
these two videos show what is going on ( without and with another sphere)
the script works by detecting touch with velocity so it could break.
Intuitively, the 2 sphere shouldn’t break but i literally don’t know what to do
Ok, I get what you mean now.
local lastvelocity = script.Parent.AssemblyLinearVelocity
script.Parent:GetPropertyChangedSignal("AssemblyLinearVelocity"):Connect(function()
if lastvelocity.Magnitude < -10 and script.Parent.AssemblyLinearVelocity.Magnitude > -1 then
-- Less than -10 means its falling fast.
-- Greater than -1 means it just landed.
-- If you only want it to break on ground impact, and not on walls. Then replace .Magnitude with .Y
end
lastvelocity = script.Parent.AssemblyLinearVelocity
end)
You could subtract its velocity with the velocity of the other part to get your desired result.
for some reasons while running it, getpropertychanged signal does not do anything and does not print things
Maybe instead of using :GetPropertyChangedSignal(), you can try a while loop, or RunService.Stepped
script.Parent.Touched:Connect(function(hit)
if hit.Parent and (hit.AssemblyLinearVelocity - script.Parent.AssemblyLinearVelocity).Magnitude > 10 then
print("Touched with at least 10 velocity")
end
end)
This will subtract the velocity like I said in the previous post.
2 Likes