Hi,

I'm trying to make a broomstick where you use "W" to move in the direction of your mouse... It does exactly what it says but it's super glitchy in a sense that if you move your mouse a tiny bit, that character starts shaking..

I would like it to become smoother but i'm unsure of what I need to do to enable that...

Any ideas?

local run = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local camera = game.Workspace.Camera
local mouse = game.Players.LocalPlayer:GetMouse()



local player = game.Players.LocalPlayer
local Root = player.Character:WaitForChild("HumanoidRootPart")
local animationTrack = player.Character.Humanoid:LoadAnimation(game.ReplicatedStorage.FlightAni)


local status = false
local active = {}
local delta = {}

local DELAY = 15
local MOD = 10

local BP_TRACK = nil



local Char = player.Character or player.CharacterAdded:Wait()

uis.InputBegan:Connect(function(input, processed)
	if processed then return end
	local key = input.KeyCode
	if not active[key] then active[key] = true end
	active[key] = true
	
	local char = player.Character
	if key == Enum.KeyCode.F then
		status = not status		
		if status then
			
			char.Humanoid.WalkSpeed = 0
			local BP = Instance.new("BodyPosition")
			BP.MaxForce = Vector3.new(10000,10000,10000)
			BP.P = 15000
			BP.Position = Char.HumanoidRootPart.Position
			BP.Parent = Char.HumanoidRootPart
			--local Broom = game.ReplicatedStorage.Broom
			--player.Character.Humanoid:AddAccessory(Broom:Clone())
			animationTrack:Play()
			
		else
			char.Humanoid.WalkSpeed = 16
			char.HumanoidRootPart.BodyPosition:Destroy()
		end
	end
end)

uis.InputEnded:Connect(function(input, processed)	
	if processed then return end
	local key = input.KeyCode
	if not active[key] then active[key] = false end
	active[key] = false
end)

run.Stepped:Connect(function(delta)
	if player then
		if player.Character then
			local hrp = player.Character.HumanoidRootPart
			local BP = hrp:FindFirstChild("BodyPosition") 
			if BP then
				Root.CFrame = CFrame.new(Root.Position, Root.Position + mouse.Hit.LookVector)
				local move_vec = Vector3.new(0,0,0)
				if active[Enum.KeyCode.W] then move_vec = move_vec + mouse.Hit.LookVector end
				if move_vec ~= Vector3.new(0,0,0) then
					BP.Position = hrp.Position + (move_vec.Unit*MOD)
				end
			end
		end
	end
end)

Please ignore the Accessory being added; that's to go into a remote at a later date!

Thank you!

1 comment

0