So im making a new game where you can fling around the map so you can traverse it, and im doing first the mechanics, but i want to know how I could make when you jump and press Q or Q and jump you can do a fling that goes a shorter distance and you can kind of control it (It's actually a roblox bug that i thought i could use to my advantage), here is the code, and give me ideas on how i could make it better!
#2 or more key inputs to do a controlled fling
1 messages · Page 1 of 1 (latest)
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = workspace.CurrentCamera
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local HRP = char:FindFirstChild("HumanoidRootPart")
local InputService = game:GetService("UserInputService")
local debounce = false
local comboWindow = 0.5 -- seconds to complete the combo
local lastjump = 0
UserInputService.InputBegan:Connect(function(input, GamePE)
if GamePE then
return
end
if input.KeyCode == Enum.KeyCode.Q then
--dont put anything in here
if debounce then return end --do it after this
local currentTime = os.clock()
if input.KeyCode == Enum.KeyCode.Space then -- if it jumped after Q, it will do a controlled fling
if currentTime - lastjump < 0.5 then
local lookDir = Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z)
local rightDir = Vector3.new(camera.CFrame.RightVector.X, 0, camera.CFrame.RightVector.Z)
HRP.AssemblyLinearVelocity = Vector3.new(camera.CFrame.LookVector.X * 10, 10, camera.CFrame.LookVector.Z * 10)
HRP.AssemblyAngularVelocity = Vector3.new(1, 0, 0)
print("2nd ability!")
end
lastjump = currentTime
end
debounce = true
--Part for when it flings
local lookDir = Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z)
local rightDir = Vector3.new(camera.CFrame.RightVector.X, 0, camera.CFrame.RightVector.Z)
print(lookDir)
HRP.AssemblyLinearVelocity = Vector3.new(camera.CFrame.LookVector.X * 100, 100, camera.CFrame.LookVector.Z * 100)
HRP.AssemblyAngularVelocity = Vector3.new(1, 0, 0)
task.wait(2) --First, waits 2 seconds
--Part where it tries to make player stand up
while hum.PlatformStand == true do
hum.PlatformStand = false
local look = HRP.CFrame.LookVector
local flatLook = Vector3.new(look.X, 0, look.Z)
char:PivotTo(CFrame.new(HRP.Position, HRP.Position + flatLook))
end
task.wait(3)
debounce = false
end
end)
add iskeydown q or iskeydown space and isjumping