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

How can I make a block break welds of parts around it without bouncing off?

Asked by
Jac_00b 157
2 years ago

Hello, I am currently making a game where a player can fire blocks from conveyors onto structures that others are standing on. These blocks will take out parts that the structure is made out of. I'm having trouble with it, however. I welded all of the parts of the building together and unanchored them. Then I made and tried the script below:

script.Parent.Touched:Connect(function(hit)
    if hit:IsA("BasePart") or hit:IsA("UnionOperation") then
        hit:BreakJoints()
    end
end)

When I tried it, the welds and parts were only moved immediately after contact with the block, causing the block to bounce back. I want the block to pass clean through, so how do you think I can accomplish this? Any help would be appreciated. Thanks.

0
You are waiting for the Block to touch and therefore decelerate. Try using Raycasts (better) or an identical invisible and no-collide block which fires 2 physics-frames earlier and Breaks the Joints (worse). You could also try to save the velocity before impact and continue it after BreakJoints. xXMadonXx 190 — 2y
0
How could I use a raycast to help? Jac_00b 157 — 2y

1 answer

Log in to vote
0
Answered by
Jac_00b 157
2 years ago

I found a solution, albeit a bit hacky. I made a wait() loop and made it so it updates a value that shows the velocity the block is at. When touched, the block gives the same velocity to the parts it touched. While it's not exactly a clear cut, it definitely knocks them down a lot better than before. Code:

local oldvelocity
while wait() do
    oldvelocity = script.Parent.Velocity
    script.Parent.Touched:Connect(function(hit)
        if hit:IsA("BasePart") or hit:IsA("UnionOperation") then
            hit:BreakJoints()
            hit.Velocity = oldvelocity
        end
    end)
end
Ad

Answer this question