How would I make a dash system?

Hello! I’m new to scripting, and it would be really helpful on how to make a dash system(4 way direction). The tutorials on Youtube aren’t really helpful at all to me.

1 Like

The easiest way is to mess with some stuff. Whatever works for you! Such as either setting the HumanoidRootPart’s Velocity to the HumanoidRootPart’s LookVector CFrame. You could even use AlignPosition in some cases.

Just have fun and take a look at the Engine Reference Guide and Roblox DevForum for other peoples experiences, and how they have solved it.

@MykoNil If you’re not going to help. Don’t post on DevForum.

2 Likes

It’s a 4 way dash system, so he won’t be using LookVector (it will just dash the player forward) instead he should check for the direction the player is moving to (no matter the LookVector) and dash on that direction.

As a matter of fact. You would still use LookVector for this situation so the Character Dashes to the Left or Right, based on Look Direction of the Character. Since LookVector is just a Direction CFrame, meaning it only goes up to a minimum of 0 and max to 1. You can just add an offset in a specific direction and then times it by how far you want to go.

Example
After 5 seconds. The player will be pushed right with a power of 500. Based on look direction of the Player.

This is using the Velocity instead of something that would be better like AlignPosition. So Player Character friction, on the ground, may make the dash less powerful.

wait(5)
local Power = 500
local Direction = Vector3.new(1,0,0) 

game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector + Direction * Power * game.Players.LocalPlayer.Character.HumanoidRootPart:GetMass()

How would the script even know which direction to dash (unless you’re saying he needs to have 4 buttons for each direction)? He can just use magnitude and check for direction the player is moving to, while only using a single button. BodyVelocity or LinearVelocity works for dashing

Well. Basing it on that it’s going to be a fighting game the camera will be third-person, and locked. Meaning the camera will be Trapped in Shift-lock.

If you wanted to dash right, you just use UserInputService to detect the a key to change the Direction to be Vector3.new(-1,0,0), and d key be Vector3.new(1,0,0). Then when they click shift, to dash, it will just use the variable direction.

My bad, Magnitude is not needed, just MoveDirection. We can use MoveDirection.X or Y to get direction using if-then checks.

He did not mention mouse-lock. And my point is that if a player is moving in a certain direction (lets say right) and presses a key, they will dash to that direction, no matter where their character is facing.

Your solution works, but it would not be friendly for mobile users

Step 1: Create a dash animation. One animation for each direction.
Create an Animation Event for when the dash movement begins.

Step 2: Create a local script parented to StarterPlayer.StarterCharacterScripts.
Create 4 Animation objects as children of the script, and paste in the published animations.

Write code to do the following in the local script:

local Char = script.Parent -- all scripts in StarterCharacterScripts are cloned into the character when it spawns
-- get Humanoid and Humanoid.Animator and HumanoidRootPart
-- load animation tracks for each animation Animator:LoadAnimation(animation)
-- get and connect to the animation events using GetMarkerReachSignal
-- when signal is fired, move the character
-- to know when to play the animation, do
local UIS = game:GetService("UserInputService")
-- connect to InputBegan and detect the inputs you want for the dash and then play the animation
-- alternatively you can use ContextActionService instead of UserInputService

Animator | Documentation - Roblox Creator Hub
AnimationTrack | Documentation - Roblox Creator Hub
GetMarkerReachedSignal
UserInputService | Documentation - Roblox Creator Hub
ContextActionService | Documentation - Roblox Creator Hub

5 Likes

Thank you for the steps. Helps a lot to know some basic steps.

1 Like

When Animating:

  • set the animation priority to “Action” or higher

    • create a “Animation Event” at the beginning of the animation for instant dash
    • publish the finished animation to the game’s group or yourself if it is under your account
      Then:
    • copy the id which is in the url of the published animation
      paste id into an Animation object
  • For moving the character:

    • consider relativity:
      • move with respect to the camera(the person’s viewpoint)
      • or the character (the direction the character is facing)
      • or to the direction of intended movement (current input)
    • consider ways to move a part:
      • Lerp the position/cframe of an invisible, non-colliding local part using TweenService
        • tie together using RigidConstraint
        • tie together using AlignPosition and/or AlignOrientation
      • RunService.Stepped
        • lerp position
          • add position diff
          • or set position
          • keep orientation?
        • lerp cframe
        • apply lerp position/cframe options to an invisible, non-colliding local part
          • tie together using RigidConstraint
          • tie together using AlignPosition and/or AlignOrientation

Basic CFraming:

-- camera's CFrame but no X or Z tilt:
local cf = workspace.CurrentCamera.CFrame
local xz_lookVector = Vector3.new(cf.LookVector.X, 0, cf.LookVector.Z)
cf = CFrame.new(cf.Position, cf.Position+xz_lookVector)
-- cf is now ready for dashing!

-- relative to character:
local cf = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
-- cf is now ready for dashing!

-- relative to intended direction:
local cf = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
local moveDir = game.Players.LocalPlayer.Character.Humanoid.MoveDirection
cf = CFrame.new(cf.Position, cf.Position + moveDir)
-- cf is now ready for dashing!

-- now you can use the following properties of a cframe:
local forward = cf.LookVector -- for forward direction
local backward = -cf.LookVector -- for backwards
local right = cf.RightVector -- for rightwards
local left = -cf.RightVector -- for left
local up = cf.UpVector -- for up?
local down = -cf.UpVector -- for down?
6 Likes

Thank you for the great help.

This is gonna help me a lot for the coding and animation

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.