#How do I make this dash system follow the camera like in strongest battlegrounds?

1 messages · Page 1 of 1 (latest)

balmy sage
#

local DashEvent = script.Parent

-- Reusable easing function
local function applyEasedVelocity(bv: BodyVelocity, direction: Vector3, strength: number, duration: number)
local steps = 10
local rate = duration / steps

for i = 1, steps do
    local t = i / steps
    local easeOut = (1 - t)^2
    local currentSpeed = strength * easeOut
    bv.Velocity = direction.Unit * currentSpeed
    task.wait(rate)
end

bv:Destroy()

end

DashEvent.OnServerEvent:Connect(function(Player, DashButton)
local Character = Player.Character
local Hum = Character:FindFirstChild("Humanoid")
local HumRp = Character:FindFirstChild("HumanoidRootPart")
if not Character or not Hum or not HumRp then return end

local function createDashEffect(direction)
    local DashEfx = script.Efx.DashEfx:Clone()
    DashEfx.Parent = HumRp
    DashEfx.EmissionDirection = direction
    DashEfx:Emit(50)

    local SoundEfx = script.Efx.Dust:Clone()
    SoundEfx.Parent = HumRp
    SoundEfx:Play()

    game.Debris:AddItem(SoundEfx, 1.4)
    game.Debris:AddItem(DashEfx, 0.5)
end

if DashButton == "WButton" then
    print("W")
    Hum:LoadAnimation(script.Animation.WDash):Play()
    createDashEffect("Back")

    local bv = Instance.new("BodyVelocity")
    bv.Name = "WDashVelocity"
    bv.MaxForce = Vector3.new(50000, 0, 50000)
    bv.Parent = HumRp
    applyEasedVelocity(bv, HumRp.CFrame.LookVector, 105, 1.2)

    -- Hitbox for damage
    local hitbox = Instance.new("Part")
    hitbox.Size = Vector3.new(4, 5, 4)
    hitbox.Transparency = 0.5
    hitbox.CanCollide = false
    hitbox.Anchored = true
    hitbox.CFrame = HumRp.CFrame * CFrame.new(0, 0, -5)
    hitbox.Parent = workspace

    local function onHit(otherPart)
        local otherChar = otherPart.Parent
        if otherChar and otherChar:FindFirstChild("Humanoid") and otherChar ~= Character then
            local enemyPlayer = game.Players:GetPlayerFromCharacter(otherChar)
            if enemyPlayer and enemyPlayer ~= Player then
                otherChar.Humanoid.Health = math.max(0, otherChar.Humanoid.Health - 10)
                if not otherChar:FindFirstChild("Stunned") then
                    local stunValue = Instance.new("BoolValue")
                    stunValue.Name = "Stunned"
                    stunValue.Parent = otherChar
                    task.delay(2, function() stunValue:Destroy() end)
                end
            end
        end
    end

    local conn = hitbox.Touched:Connect(onHit)
    task.wait(0.3)
    conn:Disconnect()
    hitbox:Destroy()

elseif DashButton == "SButton" then
    print("S")
    Hum:LoadAnimation(script.Animation.SDash):Play()
    createDashEffect("Front")

    local bv = Instance.new("BodyVelocity")
    bv.Name = "SDashVelocity"
    bv.MaxForce = Vector3.new(50000, 0, 50000)
    bv.Parent = HumRp
    applyEasedVelocity(bv, -HumRp.CFrame.LookVector, 105, 1.2)

elseif DashButton == "AButton" then
    print("A")
    Hum:LoadAnimation(script.Animation.ADash):Play()
    createDashEffect("Right")

    local bv = Instance.new("BodyVelocity")
    bv.Name = "ADashVelocity"
    bv.MaxForce = Vector3.new(50000, 0, 50000)
    bv.Parent = HumRp
    applyEasedVelocity(bv, -HumRp.CFrame.RightVector, 70, 0.6)

elseif DashButton == "DButton" then
    print("D")
    Hum:LoadAnimation(script.Animation.DDash):Play()
    createDashEffect("Left")

    local bv = Instance.new("BodyVelocity")
    bv.Name = "DDashVelocity"
    bv.MaxForce = Vector3.new(50000, 0, 50000)
    bv.Parent = HumRp
    applyEasedVelocity(bv, HumRp.CFrame.RightVector, 70, 0.6)
end

end)

pseudo widget
#

Like in first person mode?

balmy sage
#

Nah nah, its third person, you know how you can control the dash depending where you face the camera in 3p?

#

I can give an example

pseudo widget
#

Also three consecutive tilda and Lua following it then another set of tilda is how you format your code of discord

balmy sage
#

Oh okay

pseudo widget
#

Yeah example might help.

balmy sage
#

Like that

#

You see how the dash follows the camera

pseudo widget
#

Oh lol do so your camera isn’t locked?

#

Like behind the character

balmy sage
#

Here ill show you the issue in my game rq

last depotBOT
#

studio** You are now Level 2! **studio

balmy sage
#

one second

pseudo widget
#

Yeah

balmy sage
#

You see how the dash is strict to one direction?

#

How do I get the motion to be like in strongest battlegrounds?

pseudo widget
#

Despite character direction

#

At the time of the dash?

balmy sage
#

Yeah, like when I foward dash, I want the player to be able to control the direction of the dash while dashing

#

Because it would be more efficient for combat

pseudo widget
#

Ohh

#

My first thought is to present a vector in the forward direction interpolate the character direction or desired player direction vector by a set amount

#

Or if you want it to be dynamic based on how perpendicular or away the player faces from the original or current dash angle you would instead take the dot product of ur two vectors then use acos(dot product value) which is ur theata and multiply by some constant

#

If you want me to get more specific on implementing it in ur code I can

balmy sage
#

You can if you want, thank you very much. Im new to coding so Ill have to read on what you just said lol

#

Im tryna make a fireforce battlegrounds game

#

and im the only scripter lol

pseudo widget
#

Nah it’s fine. I’m on my phone so code snippets r a bit hard

balmy sage
#

Do you know anything about on how to try and get a team to help?

#

Money a bit tight for me rn cause im abt to go to college

#

Does this server help with that

pseudo widget
#

I’m broke too, I just sent a key in find-a-team myself. you can present your game as a passion project and your looking for members

balmy sage
#

Okay bet, what kind of game are you looking to work on

pseudo widget
#

I’m making a Civil War top down shooter, ofc I can get more detailed but the plan for it is sick

#

I jus have a problem over optimizing problems so it lowkey taking a bit, I got a couple scripters but they are a lil less experience

balmy sage
#

Ohhh

#

that sounds really cool

pseudo widget
#

Ur problem tho, I’ll make a snippet in a lil, you first get your humanoid root part.CFrame LookVector ur desired player vector take the dot product of your current desired and the current dash vector, make sure both vectors are units. And be sure to clamp it “math.clamp(fowardVec:Dot(want), -1, 1)” then get ur theata or change in direction from the forward vex to new desired by math.acos(dot product value) then I would normalize your difference so it is more predictable and avoid loops in ur unit circle basically. So “fowardVec:Lerp(desiredVec, theata / math.pi) and then set that value equal to ur current forward vec and set your body velocity with ur foward vec

#

lol sorry if I was on my computer I’d be more help

balmy sage
#

No its okay, thank you for helping me!

pseudo widget
#

Here’s a pic of the math

#

The | is the magnitude of the vector

balmy sage
#

Okay, thank you

finite hornet
#

I recommend making the dash system client sided imo as its more smoother and less latency (less delay) from local script

finite hornet
#

everything came from there, i just summarize

pseudo widget
#

We if you want efficrntcy you could prolly just calculate it your self with fowardVec*(1-(theta / math.pi)) + desiredVec*(theata / math.pi) and it will do the same as Lerp minus the function overhead prolly