i’ve made a script that is supposed to offset parts of a car depending on their velocity, giving it a “deforming” effect, but its either a 0.1 stud difference, or it literally explodes if you hit it the wrong way. can someone help me figure out where i went wrong?
function onHit(v,hit)
damagedparts=workspace:GetPartBoundsInRadius(v.Position,(math.abs(math.floor(v.Velocity.Magnitude-hit.Velocity.Magnitude)))/3)
for i,v2 in damagedparts do
if v2:IsDescendantOf(script.Parent) and v2.Name ~= "chassis" then
v2.Position += Vector3.new((v.AssemblyLinearVelocity.X)/10,(v.AssemblyLinearVelocity.X)/10,(v.AssemblyLinearVelocity.X/10))
print(CFrame.new((v.Velocity.X-hit.Velocity.X),(v.Velocity.X-hit.Velocity.Y),(v.Velocity.X-hit.Velocity.Z)).Position)
end
end
end
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(hit)
onHit(v,hit)
end)
end
end
also it always ends up going in the wrong direction for whatever reason