I’ve tried many iterations of other peoples directional movement / dodgeroll systems using specifically LinearVelocity (since BodyVelocity is deprecated). However I cannot get the movement direction consistent. “Forwards” & “Backwards” are near perfectly consistent but both sideways directions seem to get confused. Script below.
Alternatively, if there is a better way to create a LinearVelocity dash I would love some advice ^^
function combatController:dodgeRoll(player, character)
local hum = character.Humanoid
local hrp = character.HumanoidRootPart
local root = hrp.RootAttachment
hum.WalkSpeed = 0
local newVel = Instance.new("LinearVelocity")
newVel.Parent = hrp
newVel.Attachment0 = root
newVel.MaxForce = math.huge
local direction = tostring(math.round(hum.MoveDirection:Dot(hrp.CFrame.LookVector)))
print(direction)
-- I really hate using tostring here but apparently 0 == -0 >:(
if direction == "1" then
direction = "forward"
elseif direction == "-1" then
direction = "backwards"
elseif direction == "0" then
direction = "left"
elseif direction == "-0" then
direction = "right"
end
print(direction)
local velocity = 50
if direction == "forward" then
newVel.VectorVelocity = hrp.CFrame.LookVector * velocity
elseif direction == "backwards" then
newVel.VectorVelocity = hrp.CFrame.LookVector * -velocity
elseif direction == "left" then
newVel.VectorVelocity = hrp.CFrame.RightVector * -velocity
elseif direction == "right" then
newVel.VectorVelocity = hrp.CFrame.RightVector * velocity
end
task.wait(.1)
newVel:Destroy()
hum.WalkSpeed = 16
end