I am trying to make a dash system where the player double clicks A or D and dashes left or right respectively. To do this I am using LinearVelocity to move the character. I am using the Plane mode to only apply velocity in 2 directions. The issue is that I want to apply on the X and Z vectors but when I change the properties to do so it doesn’t work as expected. Instead applies velocity on the Y-axis and X-axis even though I set it to only do the X-axis and Z-axis.
playerEvent.OnServerEvent:Connect(function(player, direction)
if debounce[player] == nil then -- check if debounce active
debounce[player] = true -- its not, so set debounce to true
local velocity = 0 -- set velocity to 0
if direction == 'Left' then
velocity = -32 -- if dashing left then set velocity to -32 (-32 studs/s left)
elseif direction == 'Right' then
velocity = 32 -- if dashing right then set velocity to 32 (32studs/s right)
end
local character = player.Character
local humanoidRootPart = character.HumanoidRootPart
local linearVelocity = humanoidRootPart:FindFirstChild('LinearVelocity')
local cf = humanoidRootPart.CFrame
if linearVelocity == nil then
linearVelocity = Instance.new('LinearVelocity')
linearVelocity.Attachment0 = humanoidRootPart.RootAttachment
linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
linearVelocity.PrimaryTangentAxis = Vector3.new(1, 0, 0) -- x-axis
linearVelocity.SecondaryTangentAxis = Vector3.new(0, 0, 1) -- z-axis
linearVelocity.MaxForce = math.huge
linearVelocity.Enabled = false
linearVelocity.Parent = humanoidRootPart
end
linearVelocity.PlaneVelocity = Vector2.new(velocity, 0) -- dash left or right
print(linearVelocity.SecondaryTangentAxis) -- prints (0, 0, 1) but still applies velocity of 0 to the y-axis ????
linearVelocity.Enabled = true
task.wait(.25) -- travels 8 studs in direction in 0.25 seconds
linearVelocity.Enabled = false
task.wait(1) -- debounce
debounce[player] = nil -- remove debounce finally
else
print('On Debounce')
end
end)
I have noted that when the relativeTo value is set to world it works but the issue is that the vectors are not relative to the attachment 0.