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

Side Dash Direction Problem?

Asked by
TopBagon 109
4 years ago

I'm trying to make a character dash on double-press (W, A, S, D). I'm using BodyVelocity inside HumanoidRootPart to dash. W Dash is pretty straight-forward, just take the lookVector, multiply by some speed and set bodyVelocity.Velocity to that. S Dash is almost the same, just multiply the lookVector by -1. Side dash is the problem though. I tried multiplying by CFrame.Angles, adding some vectors but couldn't make it work, here's the simplified version of my code:

01local dashRemote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes").Dash
02local speed = 100
03local timeNeeded = 0.25
04local dirs = {
05    ['a'] = CFrame.Angles(-90, 0, 0),
06    ['d'] = CFrame.Angles(90, 0, 0),
07    ['w'] = 1,
08    ['s'] = -1,
09}
10 
11 
12dashRemote.OnServerEvent:Connect(function(plr, key)
13    local root = plr.Character.HumanoidRootPart
14    local direction = dirs[string.char(key):lower()]
15    local velocity = Instance.new("BodyVelocity", root)
16    velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
17    velocity.Velocity = root.CFrame.lookVector * direction * speed
18 
19    delay(timeNeeded, function() velocity:Destroy() end)
20end)

Any kind of help is appreciated, Thanks.

0
Why you using string.char? just use string.lower(key) GravityGouse99938 75 — 4y
0
Because that key is an integer (I got it from KeyCode.Value), so to turn integer into character I'm using string.char TopBagon 109 — 4y

Answer this question