How to make swipe up to jump

I want mobile players to be able to jump when they swipe up. Idrk understand how I would even go about this. So any help would be appreicated

1 Like

Try this as a LocalScript in StarterGui. Iā€™m not entirely sure if they will work, so just report any errors that occur if that happens.

local UIS = game:GetService("UserInputService")

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid").Health

UIS.TouchSwipe:Connect(function(SwipeDirection)
	if Character and Humanoid.Health > 0 then
		if SwipeDirection == Enum.SwipeDirection.Up then
			Humanoid.Jump = true
		end
	end
end)
1 Like

this needs removed for no error

1 Like

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

-- Variables to track swipe
local swipeThreshold = 50  -- Minimum vertical distance (in pixels) for swipe to trigger jump
local startPos = nil

-- Function to detect touch start (for swipe start position)
local function onTouchBegan(input)
    if input.UserInputType == Enum.UserInputType.Touch then
        startPos = input.Position  -- Store the starting position of the touch
    end
end

-- Function to detect touch end (for swipe end position)
local function onTouchEnded(input)
    if input.UserInputType == Enum.UserInputType.Touch and startPos then
        local delta = input.Position - startPos  -- Calculate the difference in position
        -- Check if the swipe is upwards and exceeds the swipe threshold
        if delta.Y < -swipeThreshold then
            -- Trigger the jump action
            Humanoid.Jump = true
        end
    end
    startPos = nil  -- Reset the start position after the touch ends
end

-- Connect the touch events
UserInputService.TouchStarted:Connect(onTouchBegan)
UserInputService.TouchEnded:Connect(onTouchEnded)

Just change the swipeThreshold if u want it to be a shorter or long swipe.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.