Vector velocity goes wrong way

I tried making a dash system and i can’t get the direction right,
for reference white parts are for showing where is the rootpart look vector times 50 is placed and red part is where it is when starting dash.

Local script

-- Services --
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

-- Things --
local Player = Players.LocalPlayer
local Character : Model = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

UserInputService.InputBegan:Connect(function(Input, Process)
	if Process then return end
	if Input.KeyCode == Enum.KeyCode.Q then
		ReplicatedStorage.Remotes.Combat.Dash:FireServer()
	end
end)

RunService.Stepped:Connect(function(Time, Delta)
	
	local Part = Instance.new("Part")
	Part.Anchored = true
	Part.Parent = game.Workspace.Folder
	Part.Size = Vector3.new(1, 1, 1)
	Part.Position = HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector * 50
	
	task.wait(0.4)
	Part:Destroy()
	
end)


Server script

-- Services --
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local VelocityService = require(ReplicatedStorage:WaitForChild("VelocityService"))
local Trash = game:GetService("Debris")

-- Things -- 
local Animations = ReplicatedStorage.Animations
local Remotes = ReplicatedStorage.Remotes

Remotes.Combat.Dash.OnServerEvent:Connect(function(Player)
	local Character : Model = Player.Character
	local HumanoidRootPart : Part = Character:WaitForChild("HumanoidRootPart")
	local RootAttachment : Attachment = HumanoidRootPart:WaitForChild("RootAttachment")
	local Humanoid : Humanoid = Character:WaitForChild("Humanoid")
	local Animator : Animator = Humanoid:WaitForChild("Animator")
	
	local DashAnimationTrack = Animator:LoadAnimation(Animations.Combat.Dash)
	DashAnimationTrack:Play()
	
	local VectorVelocity = HumanoidRootPart.CFrame.LookVector * 50
	
	local Part = Instance.new("Part")
	Part.Anchored = true
	Part.Parent = game.Workspace.Folder
	Part.Size = Vector3.new(2,2,2)
	Part.Color = Color3.new(1, 0, 0.0156863)
	Part.Position = HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector * 50
	Trash:AddItem(Part, 0.1)
	
	local Velocity = VelocityService:Create(HumanoidRootPart, RootAttachment, 10000, VectorVelocity, false)
	VelocityService:Start(Velocity)
	
	
	DashAnimationTrack.Stopped:Connect(function()
		VelocityService:Stop(Velocity)
	end)
	
end)

Module

local VelocityService = {}

function VelocityService:Create(Parent : Instance, Attachment0 : Attachment, MaxForce : number, VectorVelocity : Vector3, StartImmediately : boolean)
	local Velocity = Instance.new("LinearVelocity")
	Velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	Velocity.Attachment0 = Attachment0
	Velocity.MaxForce = MaxForce
	Velocity.Enabled = false
	Velocity.Visible = true
	Velocity.VectorVelocity = VectorVelocity
	Velocity.Parent = Parent
	if StartImmediately == true then
		Velocity.Enabled = true
	end
	
	return Velocity

end

function VelocityService:Start(Velocity : LinearVelocity)
	Velocity.Enabled = true
end

function VelocityService:Stop(Velocity : LinearVelocity)
	Velocity.Enabled = false
end

function VelocityService:Destroy(Velocity : LinearVelocity)
	Velocity:Destroy()
end

function VelocityService:Delay(Velocity : LinearVelocity, DelayTime : number)
	Velocity.Enabled = false
	task.delay(Velocity.DelayTime, function()
		Velocity.Enabled = true
	end)
end

return VelocityService

Your attachment is probably backwards. Change RelativeTo from Attachment0 to world, that should fix your problem. Cheers!

2 Likes

Is there a way to stay with relative to attachment? now it goes there but it doesn’t rotate with my character.

Even though you didn’t solve my problem, you were the only one to answer. You get a free solution

Yeah, rotate the attachment itself. I usually leave velocity calculations relative to the world for simplicity though

lol thank you I appreciate it aijwdij

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