Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Dashing W,A,S,D system: How can I make this better / Smoother?

Asked by 6 years ago

I have created a W,A,S,D double tap dashing system. One big problem is I'm not sure the best way to do this. Some have told me to do Char.HumanoidRootPart.Velocity and boost the player like that and some have said "Use body Velocity". At this point, I have used Velocity on parts (so no BodyVelocity). It works to a degree but I hope to make it smoother and better as I have seen better.

Currently how each looks like.

W: https://gyazo.com/a4a87de832911a90e864694c48aad88b As seen it is buggy, sometimes flinging you upwards and sometimes only moving a small distance.

A: https://gyazo.com/ca04894d382f42143c6c292b907afa04 Moving very little but if I jump i move further (this applies to all W a s d). This is because gravity

S: https://gyazo.com/9a55683bfd3c91f99120ac8b8472b9f0 S is pretty much broken, flinging you forward as you go back?

D: https://gyazo.com/c10a7c2d026696df3239336091bea291 D is similar to A where moves very little.

All of these use the same code but different variables and Velocity.

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EffectDictionary = require(ReplicatedStorage.ModuleScripts.EffectDictionary)
local Dashes = {
    DashW = ReplicatedStorage.RemoteEvents.Other.DashW;
    DashA = ReplicatedStorage.RemoteEvents.Other.DashA;
    DashS = ReplicatedStorage.RemoteEvents.Other.DashS;
    DashD = ReplicatedStorage.RemoteEvents.Other.DashD;
}
local DashDebounceW = true
local lastpressw
game:GetService("UserInputService").InputBegan:Connect(function(key,istyping)
    if not istyping then
        if key.KeyCode == Enum.KeyCode.W then
            if lastpressw and tick() - lastpressw <= 0.5 and DashDebounceW then
                DashDebounceW = false
                local mouse = plr:GetMouse()
                lastpressw = nil
                Dashes.DashW:FireServer(mouse.Hit)
                Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.Velocity + ((Char.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(45), 0, 0)).lookVector * EffectDictionary.DashingMultiplier)
                wait(0.5)
                DashDebounceW = true
            else
                lastpressw = tick()
            end
        end
    end
end)

Since Velocity is done here Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.Velocity + ((Char.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(45), 0, 0)).lookVector * EffectDictionary.DashingMultiplier) There is no need for server script.

Since S is completely broken:

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EffectDictionary = require(ReplicatedStorage.ModuleScripts.EffectDictionary)
local Dashes = {
    DashW = ReplicatedStorage.RemoteEvents.Other.DashW;
    DashA = ReplicatedStorage.RemoteEvents.Other.DashA;
    DashS = ReplicatedStorage.RemoteEvents.Other.DashS;
    DashD = ReplicatedStorage.RemoteEvents.Other.DashD;
}
local DashDebounceS = true
local lastpresss
game:GetService("UserInputService").InputBegan:Connect(function(key,istyping)
    if not istyping then
        if key.KeyCode == Enum.KeyCode.S then
            if lastpresss and tick() - lastpresss <= 0.5 and DashDebounceS then
                DashDebounceS = false
                local mouse = plr:GetMouse()
                lastpresss = nil
                Dashes.DashS:FireServer(mouse.Hit)
                Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.Velocity + ((Char.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(-45), 0, 0)).lookVector * -EffectDictionary.DashingMultiplier)
                wait(0.5)
                DashDebounceS = true
            else
                lastpresss = tick()
            end
        end
    end
end)

Same code but different line for velocity and different variables.

I hope someone would assist me on making this better (I care about efficiency as well). Thank you in advance. Hopefully this will get fixed.

1 answer

Log in to vote
1
Answered by 6 years ago

I honestly don't like to mess with body velocities/ just setting the velocity for players because it just doesn't work out well.

I tried to make knockback for a 2-d fighting game with velocities, and it didn't go very well. Working sometimes, beautifully, most of the time being wonky.

I would recommed using lerp to create the dash.

Essentialy, first cast a ray from the current player position to the end position you want for the dash, then check if there is a part on the ray other than the player using the find part on ray function.

If there isn't anything, lerp the primary part of the character towards the end position while playing the animations, etc.

if there is something, get distance from the player's head to the primary part, then do

Distance = --Head to Primary part

PartonRay = --The part on the ray, duh

Postion = PartonRay.Position

Position = PartonRay.Position + Vector3.new(0,0,Distance * -1)

and lerp as if nothing was in the way.

Btw you can use tweenservice too instead of lerping, whatever you prefer.

Ad

Answer this question