I am trying to apply velocity to character’s HumanoidRootPart.CFrame.lookVector, however, when I equip a tool that has a handle and add LinearVelocity, it no longer gets applied to lookVector, but somehow slightly sideways instead.
Perhaps I am doing something wrong, please let me know. This also continues happening even if I unequip the tool with handle, which really confuses me.
Tool, without a handle, that applies velocity to RootPart’s lookVector, notice how player keeps moving the same direction:
Tool with a handle, that applies velocity to RootPart’s lookVector, notice how player moving direction slightly changes:
This is the code:
local function createVelocity(part, velocitySize, duration)
local Attachment = Instance.new("Attachment", part)
local LV = Instance.new("LinearVelocity", Attachment)
LV.MaxForce = 2000 * part.AssemblyMass
LV.VectorVelocity = part.CFrame.lookVector * velocitySize
LV.Attachment0 = Attachment
game.Debris:AddItem(Attachment, duration)
end
tool.Activated:Connect(function()
local character = tool.Parent
local rootPart = character.HumanoidRootPart
createVelocity(rootPart, 20, 0.25)
end)
Thanks for the reply. I tried it, but it made no difference. Here’s how I modified “createVelocity” function based on your suggestion:
local function createVelocity(part, velocitySize, duration)
local Attachment = Instance.new("Attachment", part)
local HandleTool = part.Parent:FindFirstChild("HandleTool")
if HandleTool then
Attachment.Position = HandleTool.Handle.CenterOfMass
end
local LV = Instance.new("LinearVelocity", Attachment)
LV.MaxForce = 2000 * part.AssemblyMass
LV.VectorVelocity = part.CFrame.lookVector * velocitySize
LV.Attachment0 = Attachment
game.Debris:AddItem(Attachment, duration)
end
Let me know if this is not what you had in mind.
EDIT: I read again what you said and tried one more thing. Since the Handle.CenterOfMass is Vector3.new(0, 0, 0) and Vector3.new(0, 0, 0) in world space is Character’s HumanoidRootPart position, I tried to set attachment position to HumanoidRootPart position:
local function createVelocity(part, velocitySize, duration)
local Attachment = Instance.new("Attachment", part)
local HandleTool = part.Parent:FindFirstChild("HandleTool")
if HandleTool then
Attachment.Position = part.Position
end
local LV = Instance.new("LinearVelocity", Attachment)
LV.MaxForce = 2000 * part.AssemblyMass
LV.VectorVelocity = part.CFrame.lookVector * velocitySize
LV.Attachment0 = Attachment
game.Debris:AddItem(Attachment, duration)
end