I wish to make a dash system that allows the player to turn during dashes. However, I do not know how I would make that be. I am using a Linear Velocity and handling the script on the server side
local linearvelocity = Instance.new("LinearVelocity")
linearvelocity.RelativeTo = Enum.ActuatorRelativeTo.World
linearvelocity.Attachment0 = HumanoidRootPart.RootAttachment
linearvelocity.MaxForce = 1000000
linearvelocity.Parent = HumanoidRootPart
local lookvector = HumanoidRootPart.CFrame.LookVector
Humanoid.WalkSpeed = 0 -- Disabling this does not fix the issue, rather makes
--the player rotate around while going in a straight line, which looks goofy.
linearvelocity.VectorVelocity = Vector3.new(lookvector.X, 0, lookvector.Z) * 40
print("DASHED")
Upon being fired, the player dashes forward but turning the camera around using ShiftLock does not change the player’s dash direction. The player would keep dashing in the direction they started dashing in until the dash ends with a
task.delay(1, function()
linearvelocity:Destroy()
end)
This halts the movement and overall renders the movement-benefit of the dash useless. How would I go about fixing it?
Every force is represented by a vector, of which represents a direction and a magnitude. You apply a dominating force to the player which specifies uninterrupted movement in a particular direction and magnitude. No re-orientation of the character will influence that vector. The only thing you can do to allow a change of direction is to continually update the force based on the current character’s direction. Do this every RunService.PostSimulation.
On another note, you’ll need to use LinearVelocity.MaxAxesForce instead, as your LinearVelocity
currently overrides gravity and prevents uphill travel. To use MaxAxesForce
, you’ll have to set the following conditions:
linearVelocity.ForceLimitsEnabled = true
linearVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
Once this has been done, zero out the Y-axis influence, and remove all other limiters:
linearVelocity.MaxAxesForce = math.huge * Vector3.new(1, 0, 1)
Is there not a better way to do this without calling RunService.PostSimulation constantly for every player that dashes? Such as maybe replacing Linear Velocity with something else like a Body Velocity?
The LinearVelocity
is the successor to the BodyVelocity
—they suffer the same “problem”. This is not an issue of features but rather a consequence of physics. There is nothing inefficient about updating the force every physics step
I see. Very well, it seems I had a momentary lapse in judgement. One more thing. Could you provide me a reason as to why this bit of code does not cancel the RunService.PostSimulation?
local test = task.spawn(function()
RunService.PostSimulation:Connect(function()
print("runservice")
end)
end)
task.delay(1, function()
task.cancel(test)
--other stuff
---other stuff x2
end)
I have never used PostSimulation before.
Your connected function is being executed in its own separate thread. The game engine does this for all functions connected to an event (RBXScriptSignal
instance). Cancelling a thread in which an event connection is made will have no effect on the event connection. To disconnect an event connection, you must store the RBXScriptConnection object returned by RBXScriptSignal:Connect, then call RBXScriptConnection:Disconnect:
local connection = RunService.PostSimulation:Connect(function(deltaTime: number)
-- ...
end)
task.wait(5)
connection:Disconnect()
This doesn’t seem to work. How am I supposed to update the direction of the linear velocity?
local connection = RunService.PostSimulation:Connect(function(deltaTime: number)
local lookvector = HumanoidRootPart.CFrame.LookVector
end)
task.delay(1, function()
connection:Disconnect()
end)