Deformation going rogue

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

Are you meant to be using AssemblyLineVelocity.X for the entire Vector3? It seems to only be deforming by the X value :slight_smile:

lol i did NOT notice that, rookie mistake
also its even more unstable after fixing it, i am scared of it

Well, its definitely deformed!

All jokes aside maybe add a debounce to the deforming or make it so the impacts of the object dont cause impacts themselves - as it seems almost recursive.


fixed it by completely rewriting line 8, thanks for helping

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.