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

Traying to make my Q key Dash Me up In the air but ,its just Teleporting me instead?

Asked by 3 years ago

all this Script is Doing is teleporting me Int the Air. I Want To make it so that it's like a Dash upwards and not a teleport meaning there is a transition how would I go on about doing that.

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

local TweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:FindFirstChild("Humanoid")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q then
        char.HumanoidRootPart.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,100.0)
    end
end)
UIS.InputEnded:Connect(function(input)

end)
0
You can use a BodyVelocity to do so. Set the Velocity to go up and remove the BodyVelocity when done. rabbi99 714 — 3y
0
Thanks but how would I add that to my scrip sorry am pretty new to scripting FilthyMonsterPlays 8 — 3y

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

The reason your code is simply teleporting you is because you are setting the HumanoidRootPart's CFrame rather than transitioning the CFrame/position.

While you may be able to accomplish the desired result using tweens, I would not recommend it. The method I would recommend is using BodyPositions and BodyGyros.

This is the way I accomplished a 'dash' effect:

--=== Services ===--

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

--=== Variables ===--

local speed = 20 -- studs per second
local total_add = 30 -- height increase in pixels per dash
local dampener = 3 -- dampener to directional travel (non-vertical travel, x and z)

local direction = nil -- defined later in the script

local bPos -- defined later
local bGyro -- defined later
local count = 0 -- used later in the script to determine how high the player has travelled

local dashDebounce = false -- ready to accept input to dash
local Player = game.Players.LocalPlayer

local char = Player.Character
repeat
    char = Player.Character
    wait()
until char ~= nil
local HRP = char:WaitForChild("HumanoidRootPart")
local humanoid = char.Humanoid

--=== Functions ===--

local function Setup()
    HRP = char:WaitForChild("HumanoidRootPart")
    direction = Vector3.new(humanoid.MoveDirection.X * speed / dampener, 0, humanoid.MoveDirection.Z * speed / dampener)
    bPos = Instance.new("BodyPosition")
    bPos.Position = HRP.Position
    bPos.Parent = HRP
    bGyro = Instance.new("BodyGyro")
    bGyro.CFrame = HRP.CFrame
    bGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
    bGyro.Parent = HRP
    humanoid.PlatformStand = true
end

local function Stop()
    bPos:Destroy()
    bGyro:Destroy()
    humanoid.PlatformStand = false
end

--=== Hooks / Main loop ===--

UIS.InputBegan:Connect(function(input,gpe)
    if not gpe and not dashDebounce then -- gpe = game processed event
        if input.KeyCode == Enum.KeyCode.Q then
            Setup()
            count = 0 -- reset the vertical distance travelled variable
            dashDebounce = true -- dashing...
        end
    end
end)

humanoid.StateChanged:Connect(function(old,new)
    if new == Enum.HumanoidStateType.Landed then
        dashDebounce = false -- ready to accept input to dash again
    end
end)

while wait(0.1) do
    if dashDebounce then
        if count < total_add then
            local increment = speed / 10
            if count + increment > total_add then
                -- End on the exact total_add amount
                increment = (count + increment) - total_add 
            end

            bPos.Position += Vector3.new(direction.X,increment,direction.Z)
            count += speed / 10
            bGyro.CFrame = CFrame.new(HRP.Position,Vector3.new(direction.X + HRP.Position.X,HRP.Position.Y,direction.Z + HRP.Position.Z))
        else
            Stop() -- Stop the dash
        end
    end
end

My general explanation of the code is this:

The player's vertical climb is speed studs per second.

The player's directional movement is equal to 1 / dampener * speed studs per second.

These variables can be altered to change the way the dash looks:

local speed = 20 -- studs per second
local total_add = 30 -- height increase in pixels per dash
local dampener = 3 -- dampener to directional travel (non-vertical travel, x and z)

If you want the player to move directly up with no directional movement, change

Pos.Position += Vector3.new(direction.X,increment,direction.Z)
count += speed / 10
bGyro.CFrame = CFrame.new(HRP.Position,Vector3.new(direction.X + HRP.Position.X,HRP.Position.Y,direction.Z + HRP.Position.Z))

to

Pos.Position += Vector3.new(0,increment,0)
count += speed / 10
bGyro.CFrame = HRP.CFrame

I would also highly recommend using an animation, because as it stands right now, the player looks stiff as a board (as a result of Humanoid.PlatformStand)

This may be confusing, and I completely get that. If you would like something explained in more detail, feel free to contact me on Discord (phxntxsmic#2021)

Ad

Answer this question