#Dash scripting pain

1 messages · Page 1 of 1 (latest)

edgy tulip
#

Been having a pain with making a celeste style dash for my 2d platformer

It only goes right heres the code

peak lotusBOT
#

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

storm spear
#

coding in arial

edgy tulip
#

in what?

cobalt flame
#

Coding in old egypt Manuscript

edgy tulip
#

Oh.

#

Uhhh

#

Had to go to mobile notes cuz pc kinda stupid

gentle forum
#

Debug lik add some prints

rapid timber
#

Unsure if this is like pseudo code

#

But its dir.Magnitude

#

So if dir.Magnitude == 0 then set dir to vector3.new(1,0,0)

storm spear
#

kinda unrelated but the default dash should probably be up or where your character is facing cus rn its always right which is kinda weird if you're facing left

edgy tulip
#

Yeah it just i kinda wanna make a 8 direction dash like

#

Up right left down ect

#

So i kinda have 0 how to make a wrap around (btw this is paired with a 2d script

#

Imma show u

#

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

repeat
wait()
until Player.Character

local Player = Player.Character
local HumanoidRootPart = Player.HumanoidRootPart

local Positioner = Instance.new("BodyPosition", HumanoidRootPart)
Positioner.MaxForce = Vector3.new(0, 0, math.huge)
Positioner.Position = Vector3.new(0, 0,HumanoidRootPart.Position.Z)

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = Player.HumanoidRootPart

game:GetService("RunService").RenderStepped:connect(function()
Camera.CFrame = CFrame.new(HumanoidRootPart.CFrame.X, HumanoidRootPart.CFrame.Y, HumanoidRootPart.CFrame.Z + 30)
Camera.FieldOfView = 50
end)

#

The 2d camera makes the player move left and right

#

But the player can still move in other directions but i kinda cant fix that

rapid timber
#

Edit that and put three ``` in front and end please

edgy tulip
#

But it limited

#

?

rapid timber
#

This will put it in a code structure

edgy tulip
#

Oh ok

rapid timber
#

local test = hi

#

You can add a lua at the end of the first three `

#

To make it colored

#

local someVariable = "hi" ```
edgy tulip
#
local Player = game.Players.LocalPlayer

repeat
wait()
until Player.Character

local Player = Player.Character
local HumanoidRootPart = Player.HumanoidRootPart

local Positioner = Instance.new("BodyPosition", HumanoidRootPart)
Positioner.MaxForce = Vector3.new(0, 0, math.huge)
Positioner.Position = Vector3.new(0, 0,HumanoidRootPart.Position.Z)

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = Player.HumanoidRootPart

game:GetService("RunService").RenderStepped:connect(function()
    Camera.CFrame = CFrame.new(HumanoidRootPart.CFrame.X, HumanoidRootPart.CFrame.Y, HumanoidRootPart.CFrame.Z + 30)
    Camera.FieldOfView = 50
end) ```
#

Thats the camera

#

And the script is to large to put into a single message so gimma asec

rapid timber
#

Please dont LOL

#

Don't need your whole game in a message, just need where the issue is. Try and pin point somewhere, but again I think your magnitude is wrong if thats what the actual code looks like

edgy tulip
#

Ok

rapid timber
#

It would make sense because that one makes it default right

edgy tulip
#

Hmmm

#

K lemme check

#
    if dir.Magnitude == 0 then
        dir = Vector3.new(1, 0, 0) -- right
    end```
#

Just checking is this have any problems.

#
    if UIS.TouchEnabled then
        local playerGui = player:WaitForChild("PlayerGui")
        local joystick = playerGui:FindFirstChild("Joystick") -- replace with your joystick GUI
        if joystick then
            local thumb = joystick:FindFirstChild("Thumb")
            local outer = joystick:FindFirstChild("Outer")
            if thumb and outer then
                local offsetX = thumb.Position.X.Offset - outer.Position.X.Offset
                local offsetY = thumb.Position.Y.Offset - outer.Position.Y.Offset
                local mag = math.sqrt(offsetX*offsetX + offsetY*offsetY)
                if mag > 0 then
                    dir = Vector3.new(offsetX/mag, offsetY/mag, 0)
                end
            end
        end
    end

    -- Default direction if no input
    if dir.Magnitude == 0 then
        dir = Vector3.new(1, 0, 0) -- right
    end

    return dir.Unit
end
#

And thats meant to make the dash go in the direction of the mobile joystick

rapid timber
#

Ah seems like you have the magnitude correct in the code

edgy tulip
#

K thank goodness

rapid timber
#

Does this work with keyboard?

edgy tulip
#

Yeah lemme get the keyboard part

rapid timber
#

Print your dir right before you return and see what it says, if its whats its suppose to be, then its not that causing issues

edgy tulip
#
    if UIS:IsKeyDown(Enum.KeyCode.W) then dir = dir + Vector3.new(0, 1, 0) end
    if UIS:IsKeyDown(Enum.KeyCode.S) then dir = dir + Vector3.new(0, -1, 0) end
    if UIS:IsKeyDown(Enum.KeyCode.A) then dir = dir + Vector3.new(-1, 0, 0) end
    if UIS:IsKeyDown(Enum.KeyCode.D) then dir = dir + Vector3.new(1, 0, 0) end
#

Oh!

#

Thx!

#

I gtg now but i will try that later!