I’m making a wind passage type ability that creates a conveyor that pushes people forward. Since using AssemblyLinearVelocity requires collisions to be on, I just apply/remove velocity with touched/touchended.
This has a couple issues though:
- It only works normally in 1 direction (because that’s where it’s facing obv) but any other direction only somewhat works but still has a bit of drag to the wrong side.
- Making it relative to Attachment1 has a weird interaction with touch/touchended, making them fire constantly which really sucks.
How would I make the LinearVelocity apply in the correct direction?
local Conveyor = script.Parent
local Velocity = script.LinearVelocity
local Attachment = script.Parent.ConveyorAttachment
local Players = {}
local ServerScriptService = game:GetService("ServerScriptService")
local CooldownModule = require(ServerScriptService.CooldownModule)
Conveyor.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild("HumanoidRootPart") and not Players[Object.Parent.Name] then
local RootPart = Object.Parent:FindFirstChild("HumanoidRootPart")
local ConveyorVelocity = Velocity:Clone()
ConveyorVelocity.Name = "ConveyorVelocity"
ConveyorVelocity.Parent = RootPart
ConveyorVelocity.Attachment0 = RootPart:FindFirstChild("Attachment")
ConveyorVelocity.Attachment1 = Attachment
print("velocity added")
Players[Object.Parent.Name] = true
end
end)
Conveyor.TouchEnded:Connect(function(Object)
if Object.Parent:FindFirstChild("HumanoidRootPart") and Players[Object.Parent.Name] then
local RootPart = Object.Parent:FindFirstChild("HumanoidRootPart")
if RootPart:FindFirstChild("ConveyorVelocity") then
RootPart:FindFirstChild("ConveyorVelocity"):Destroy()
print("velocity removed")
Players[Object.Parent.Name] = false
end
end
end)