I am creating a dash mechanic in my game, and im trying to apply gravity to the LinearVelocity im using to move the player.
I am trying to add gravity by using the plane mode, but it doesn’t seem to be working. I do not think I am doing it right.
I am currently trying to apply the code from this page into my script, but I do not think I am doing it right.
The front dash using BodyVelocity was because I was trying to see if I could use BodyVelocity for it, but it is deprecated, and I dont want to risk messing up my game when it gets removed.
This is my first ever topic created, so I dont know whether im doing this right, and im sorry If i messed anything up, but I would like if someone helped me with my issue.
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input,gameProcessedEvent)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char.Humanoid
if input.KeyCode == Enum.KeyCode.Q then
local cam = workspace.CurrentCamera
local moveDirection = cam.CFrame:VectorToObjectSpace(hum.MoveDirection)
local left = math.round(moveDirection.X) == -1
local right = math.round(moveDirection.X) == 1
local front = math.round(moveDirection.Z) == -1
local back = math.round(moveDirection.Z) == 1
local idle = moveDirection.Magnitude == 0
if front then
print("dashing front")
local bv = Instance.new("BodyVelocity", char.HumanoidRootPart)
bv.P = math.huge
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = Vector3.new(0, 0, -60)
wait(0.35)
bv.Parent = nil
elseif back then
print("dashing back")
local lv = Instance.new("LinearVelocity")
local attch = Instance.new("Attachment", char.HumanoidRootPart)
attch.WorldPosition = char.HumanoidRootPart.AssemblyCenterOfMass
lv.Parent = char.HumanoidRootPart
lv.Attachment0 = attch
lv.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
lv.MaxForce = math.huge
lv.PrimaryTangentAxis = Vector3.new(1, 0, 0)
lv.SecondaryTangentAxis = Vector3.new(0, 0, 1)
lv.PlaneVelocity = Vector2.new(50, 0)
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
wait(0.35)
lv.Parent = nil
elseif left then
print("dashing left")
local lv = Instance.new("LinearVelocity")
lv.Parent = char.HumanoidRootPart
lv.Attachment0 = char.HumanoidRootPart.RootAttachment
lv.MaxForce = math.huge
lv.VectorVelocity = Vector3.new (-90, 0, 0)
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
wait(0.1)
lv.Parent = nil
elseif right then
print("dashing right")
local lv = Instance.new("LinearVelocity")
lv.Parent = char.HumanoidRootPart
lv.Attachment0 = char.HumanoidRootPart.RootAttachment
lv.MaxForce = math.huge
lv.VectorVelocity = Vector3.new (90, 0, 0)
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
wait(0.1)
lv.Parent = nil
elseif idle then
print("not doing anything")
local lv = Instance.new("LinearVelocity")
lv.Parent = char.HumanoidRootPart
lv.Attachment0 = char.HumanoidRootPart.RootAttachment
lv.MaxForce = math.huge
lv.VectorVelocity = Vector3.new (0, 0, -60)
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
wait(0.35)
lv.Parent = nil
end
end
end)