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

How would I make this Wall Jump/Double Jump script mobile compatible?

Asked by 4 years ago
Edited 4 years ago

I want to make it to where players on mobile can simply tap their jump button twice to double jump, but I don't know how to do that.

wait(2)

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass('Humanoid')
local Root = Character.PrimaryPart
local root = Character.HumanoidRootPart
local yaxis = 0
local o = 0
local Db = true
local CanDouble = true
local LatestPart = nil
local mouse = Player:GetMouse()
local wallJumpTopAnimTrack = Humanoid:LoadAnimation(script.WallJumpTopAnim)
local wallJumpAnimTrack = Humanoid:LoadAnimation(script.WallJumpAnim)
local doubleJumpAnimTrack = Humanoid:LoadAnimation(script.DoubleJump)
local landAnimTrack = Humanoid:LoadAnimation(script.LandAnim)
landAnimTrack.Priority = Enum.AnimationPriority.Action
local doublecd = true
local FallEffect = false

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Space and Humanoid:GetState() == Enum.HumanoidStateType.Freefall and Db then

    local ray = Ray.new(Root.Position, Root.CFrame.lookVector*2.5)
    local hit = game.Workspace:FindPartOnRay(ray, Character)

    if hit then
        if hit:IsA("BasePart") and hit.CanCollide == true then

        spawn(function()
        Db = false
        wait(0)
        Db = true
        end)
        if (hit.Position.Y + (hit.Size.Y / 2)) - Root.Position.Y <= 10 then
            wallJumpTopAnimTrack:Play()
            Character.Humanoid.AutoRotate = false
            Root.Anchored = true
            wait(0.2)
            FallEffect = true
            Root.Anchored = false
            Character.Humanoid.AutoRotate = true
            Root.Velocity = Vector3.new(0,75,0) -- was 0,75,0
            return
        end

        if LatestPart ~= hit then
        wallJumpAnimTrack:Play()
        Character.Humanoid.AutoRotate = true
        Root.Anchored = true
        wait(0.15) -- was .15
        script.Remotes.Walljump:FireServer()
        Root.Anchored = false
        FallEffect = true
        Character.Humanoid.AutoRotate = true  --was 45 v           --65
        Root.Velocity = Root.CFrame.lookVector * -57 + Vector3.new(0,113,0)
        end

        end

    else
        if Humanoid.Health < 35 then return end
        if not CanDouble then return end
        if not doublecd then return end
        doublecd = false
        spawn(function()
            wait(0)
            doublecd = true
        end)
        CanDouble = false
        Root.Velocity = Vector3.new(0,65,0)
        doubleJumpAnimTrack:Play()
        FallEffect = true
        spawn(function()
            doubleJumpAnimTrack.Stopped:Wait()
            if Db == false then
            Db = true
            landAnimTrack:Play()
            end
        end)
    end

end
end)



mouse.KeyDown:connect(function(key) 
    if key == " " then

        spawn(function()
            repeat wait() until Humanoid.FloorMaterial ~= Enum.Material.Air
            LatestPart = nil
            CanDouble = true
        end)

    end
end)

repeat wait() until Character

function fallcheck()

if root.Position.Y > 40 then
 --game.ReplicatedStorage.Events.FallDamage:FireServer(o)
 end
 o = root.Position.Y
end

Humanoid.StateChanged:connect(function(Oldstate, Newstate)
if Newstate == Enum.HumanoidStateType.Landed then
local NewYAxis = root.Position.Y
--print(yaxis - NewYAxis)

if FallEffect == true or yaxis - NewYAxis >= 10 then
    Humanoid.WalkSpeed = 0
    Humanoid.JumpPower = 0
          fallcheck()
      local a = Humanoid:LoadAnimation(script.LandAnim)
      a:Play(0.15, 1, 1)
    local Effect = game.ReplicatedStorage.FallPart:Clone()
    local Sound = game.ReplicatedStorage.Sounds.Land:Clone()
    Effect.Parent = workspace
    Effect.CFrame = root.CFrame * CFrame.new(0,-2.5,0)
    Effect.Smoke:Emit(50)
    Sound.Parent = workspace
    Sound:Play()
    game.Debris:AddItem(Sound, 4)
    game.Debris:AddItem(Effect, 4)
    wait(.05)
    Effect.Smoke.Enabled = false
    wait(.2)
    Humanoid.JumpPower = 50
    Humanoid.WalkSpeed = 16
    FallEffect = false
    end

end
if Newstate == Enum.HumanoidStateType.Freefall then
    yaxis = root.Position.Y
end
end)

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
4 years ago
Edited 4 years ago

Instead of using mouse.KeyDown, use ContextActionService:BindAction() with Enum.PlayerActions.CharacterJump.

local CAS = game:GetService("ContextActionService")

CAS:BindAction("WallJump", function (name, state, input)
    if  Humanoid:GetState() == Enum.HumanoidStateType.Freefall and Db then

    local ray = Ray.new(Root.Position, Root.CFrame.lookVector*2.5)
    local hit = game.Workspace:FindPartOnRay(ray, Character)

    if hit then
        if hit:IsA("BasePart") and hit.CanCollide == true then

        spawn(function()
        Db = false
        wait(0)
        Db = true
        end)
        if (hit.Position.Y + (hit.Size.Y / 2)) - Root.Position.Y <= 10 then
            wallJumpTopAnimTrack:Play()
            Character.Humanoid.AutoRotate = false
            Root.Anchored = true
            wait(0.2)
            FallEffect = true
            Root.Anchored = false
            Character.Humanoid.AutoRotate = true
            Root.Velocity = Vector3.new(0,75,0) -- was 0,75,0
            return
        end

        if LatestPart ~= hit then
        wallJumpAnimTrack:Play()
        Character.Humanoid.AutoRotate = true
        Root.Anchored = true
        wait(0.15) -- was .15
        script.Remotes.Walljump:FireServer()
        Root.Anchored = false
        FallEffect = true
        Character.Humanoid.AutoRotate = true  --was 45 v           --65
        Root.Velocity = Root.CFrame.lookVector * -57 + Vector3.new(0,113,0)
        end

        end

    else
        if Humanoid.Health < 35 then return end
        if not CanDouble then return end
        if not doublecd then return end
        doublecd = false
        spawn(function()
            wait(0)
            doublecd = true
        end)
        CanDouble = false
        Root.Velocity = Vector3.new(0,65,0)
        doubleJumpAnimTrack:Play()
        FallEffect = true
        spawn(function()
            doubleJumpAnimTrack.Stopped:Wait()
            if Db == false then
            Db = true
            landAnimTrack:Play()
            end
        end)
    end

end

    return Enum.ContextActionResult.Pass
end, false, Enum.PlayerActions.CharacterJump)

This should handle all methods of jumping on all platforms. Edit: Replace the UIS.InputBegan handler with this

0
What would this look like in the script above? I tried inserting it into it but It doesn't work. Justingamer700 114 — 4y
0
Updated answer compUcomp 417 — 4y
Ad

Answer this question