.Touched delayed when part uses Linear Velocity

I’ve been working on a tower defense game in which the enemies can damage the towers. The problem is whenever fast enemies come into contact with towers, there is a huge delay. I’ve attached my code as well as a video of the problem. The video may appear laggy, but it was not when it was recorded.

local Enemy = Instance.new("Part", workspace)
Enemy.Name = "Brute"
Enemy.Size = Vector3.new(4, 9, 4)
Enemy.Transparency = 0.5
Enemy.Color = Color3.fromRGB(255, 0,50)
Enemy.CanCollide = false
Enemy.Anchored = true
Enemy.Position = Vector3.new(2, 4.5, -78)

local Attachment0 = Instance.new("Attachment", Enemy)

local Velocity = Instance.new("LinearVelocity", Enemy)
Velocity.Attachment0 = Attachment0
Velocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
Velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
Velocity.MaxForce = math.huge
Velocity.VectorVelocity = Vector3.new(0, 0, 50)

Enemy.Touched:Connect(function(Hit) 
	if Hit.Name == "Tower" then 
		Enemy.Anchored = true 
	end 
end)

You can just use Tweenservice, it can be easier than linear velocity

local TweenService = game.TweenService

local Destination = workspace.Destination -- Set This to where it should go
local Speed = 20

local Tween1 = TweenService:Create(Enemy,TweenInfo.new((Enemy.Position - Destination.Position).Magnitude/Speed,Enum.EasingStyle.Linear),{Position = Vector3.new(Destination.Position.X,Enemy.Position.Y,Destination.Position.Z)})

Tween1:Play()

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