I’m using vectorForce which has a problem, it doesn’t push you as far when you’re on the ground vs when you’re in the air. Is there any better way to make a dashing/dodging system
local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local totalCharMass = 0
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Q then
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
totalCharMass = totalCharMass + v:GetMass()
end
end
local hmdrootpart = char:FindFirstChild("HumanoidRootPart")
local hmd = char:FindFirstChildOfClass("Humanoid")
local VectorForce = Instance.new("VectorForce")
VectorForce.Parent = hmdrootpart
VectorForce.Attachment0 = hmdrootpart.RootAttachment
VectorForce.Force = Vector3.new(0, 0, -500 * totalCharMass)
game.Debris:AddItem(VectorForce, 0.1)
totalCharMass = 0
end
end)
HumanoidRootPart.Velocity = -- whatever velocity you want
Velocity of a basepart is deprecated, but the reason i prefer using it over anything else, is because it is lot less laggy. If you re making a combat system this might be a good solution.
However I myself am looking for better solutions if there are any, hit me up
try using LinearVelocity. body velocity was my go-to option for dashing before it was deprecated. LinearVelocity is supposed to be a replacement for it.
something like this should be fine in your case. also instead of creating a new one every time, it’d be a better idea to insert a body mover once - when the character gets added, then just set max force to 0 instead of destroying it
local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.Q then
local hmdrootpart = char:FindFirstChild("HumanoidRootPart")
local hmd = char:FindFirstChildOfClass("Humanoid")
local totalCharMass = hmdrootpart.AssemblyMass
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Line
linearVelocity.MaxForce = math.huge
linearVelocity.LineDirection = hmdrootpart.CFrame.LookVector
linearVelocity.LineVelocity = 10 * totalCharMass
linearVelocity.Attachment0 = hmdrootpart:FindFirstChildOfClass('Attachment')
linearVelocity.Parent = hmdrootpart
game.Debris:AddItem(linearVelocity, 0.1)
end
end)
I’d like to make two suggestions. One modifies the Velocity of the character’s HumanoidRootPart locally, while the other fires a RemoteEvent and has the server place a BodyVelocity inside the characters HumanoidRootPart.
The advantage of altering the character’s velocity from a local script is that it is simply faster and smoother in game. However, because it’s done locally, exploiters could potentially get around the game’s “Energy” requirement by recycling the code and running it themselves, and the advantage of using the server to build a BodyVelocity is that the server can check for energy first, which prevents exploiters from spamming the dash. The disadvantage is that it does not feel as natural as simply changing the velocity of the characters from a local script.
The exploiters’ disadvantage occurs since their character already possesses NetworkOwnership, hence I prefer the first option. It’s pointless to have it in place on the server because exploiters will do it anyway. The most you can do is keep a watch on them through the server to ensure they don’t go too far. It’s fantastic, and I prefer it rather than body velocity.
it’d be better to use AssemblyLinearVelocity instead of Velocity as that’s deprecated.
but devhub discourages setting the velocity property so I tend to avoid it
we don’t want “instantaneous change in velocity” so VectorForce or ApplyImpulse won’t work in this case. that just leaves the body mover option.
simply setting the velocity is not a terrible choice but if you can it’s preferred to use body movers as they’re more optimized for such work.
This seems to work, i was hesitant about using this method at first, since in my older project, it causes problem when i dash into wall, the character would ragdoll. It doesn’t seems to be now