I’m trying to find the direction the camera moves, Like left right up down
I want to have my glider rotate depending on which direction the camera moves
I tried subtracting the cameras previous lookvector with the current lookvector (x and y) but that didn’t work the way I intended
local InputService = game:GetService("UserInputService")
local GliderBool = false
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Character = workspace:WaitForChild(Player.Name)
local CurrentCamera = workspace.CurrentCamera
local RS = game:GetService("RunService")
local Tween = game:GetService("TweenService")
local HRP = Character:WaitForChild("HumanoidRootPart")
local GliderRE = game.ReplicatedStorage.Glider
local DestroyGliderRE = game.ReplicatedStorage.DestroyGlider
local GliderRestraint = Player.PlayerGui.GliderRestraint
local Cursor = GliderRestraint.Outer.Cursor
local CenterCursor = Cursor.CenterCursor
local CoolDown = true
local StartInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local StartGoal = {}
StartGoal.CameraOffset = Vector3.new(0, -10, 5)
local EndInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local EndGoal = {}
EndGoal.CameraOffset = Vector3.new(0, 0, 0)
local StartGliderInfo = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local StartGliderGoal = {}
StartGliderGoal.TextTransparency = 0
StartGliderGoal.BackgroundTransparency = 0.5
local StartGliderReady = Tween:Create(Player.PlayerGui.GliderReady.TextLabel, StartGliderInfo, StartGliderGoal)
local EndGliderInfo = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local EndGliderGoal = {}
EndGliderGoal.TextTransparency = 1
EndGliderGoal.BackgroundTransparency = 1
local EndGliderReady = Tween:Create(Player.PlayerGui.GliderReady.TextLabel, EndGliderInfo, EndGliderGoal)
local CoolDownImageInfo = TweenInfo.new(120, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local CoolDownImageGoal = {}
CoolDownImageGoal.Offset = Vector2.new(0,1)
local CoolDownImageTween = Tween:Create(Player.PlayerGui.GliderReady.Frame.Frame.UIGradient, CoolDownImageInfo, CoolDownImageGoal)
InputService.InputBegan:Connect(function(key, gameProcessedEvent)
if gameProcessedEvent then return end
if key.KeyCode == Enum.KeyCode.Two then
if CoolDown then
CoolDown = false
GliderBool = true
local HRPPreviousPositionY = HRP.CFrame.Y
local PreviousMouseDelta = InputService:GetMouseDelta()
InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local Glider = Character:WaitForChild("Glider")
local Attachment = Instance.new("Attachment")
Attachment.Parent = HRP
local AlignOrientation = Instance.new("AlignOrientation")
AlignOrientation.Parent = HRP
AlignOrientation.Attachment0 = Character.UpperTorso.BodyBackAttachment
AlignOrientation.Attachment1 = Glider:WaitForChild("Turn").Attachment1
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Parent = HRP
Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
wait(.1)
for i,v in pairs(Character.Humanoid:GetPlayingAnimationTracks()) do
print(v)
v:Stop()
end
local ChangeCameraOffset = Tween:Create(Character.Humanoid, StartInfo, StartGoal)
ChangeCameraOffset:Play()
local Render = RS.RenderStepped:Connect(function(dt)
--GliderBool prevents this from running when another tool is using renderstepped
if GliderBool then
local Direction = CFrame.new(HRP.Position, Mouse.Hit.Position).LookVector
--local MouseY = math.clamp(Mouse.Y, -180, 180)*-1/10
--local MouseX = math.clamp(Mouse.X, -180, 180)*-1/10
local ViewportY = CurrentCamera.ViewportSize.Y/2
local ViewportX = CurrentCamera.ViewportSize.X/2
local MouseY = (Mouse.Y - ViewportY) / 10
local MouseX = (Mouse.X - ViewportX) * -1
local MouseXClamp = math.clamp(MouseX, -90, 90)
local MouseYClamp = math.clamp(MouseY, -180, 180)
local MouseDistanceFromCenter = Vector2.new(Mouse.X, Mouse.Y)
local HRPCurrentPositionY = HRP.CFrame.Y
local HRPDifference = HRPPreviousPositionY - HRPCurrentPositionY
local CurrentMouseDelta = InputService:GetMouseDelta()
local TurnX = 0
local TurnY = 0
local CameraCurrentOrientationX, CameraCurrentOrientationY, CameraCurrentOrientationZ = CurrentCamera.CFrame:ToEulerAnglesXYZ()
local CurrentOrientation = CurrentCamera
Cursor.Position = UDim2.new(MouseDistanceFromCenter)
--HRP.CFrame = CFrame.new(HRP.Position, Vector3.new(Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z)) * CFrame.Angles(math.rad(-90), 0, 0)
local CurrentGliderYOrientation = Glider.Turn.CFrame.Y
print(math.abs(PreviousMouseDelta.Y) - math.abs(CurrentMouseDelta.Y))
if math.abs(PreviousMouseDelta.Y) - math.abs(CurrentMouseDelta.Y) > 0 then
TurnX = 1
elseif math.abs(PreviousMouseDelta.Y) - math.abs(CurrentMouseDelta.Y) < 0 then
TurnX = -1
else TurnX = 0
end
Glider.Turn.CFrame = CFrame.new(Glider.Turn.Position, Vector3.new(Mouse.Hit.X, Glider.Turn.Position.Y, Mouse.Hit.Z)) * CFrame.Angles(0,math.rad(-90), 0) * CFrame.Angles(math.rad(math.rad(TurnX*40)), 0, math.rad(0))
HRPPreviousPositionY = HRP.CFrame.Y
PreviousMouseDelta = InputService:GetMouseDelta()
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = Direction * 40
end
end)
wait(10)
GliderBool = false
DestroyGliderRE:FireServer()
InputService.MouseBehavior = Enum.MouseBehavior.Default
local ChangeCameraOffsetEnd = Tween:Create(Character.Humanoid, EndInfo, EndGoal)
ChangeCameraOffsetEnd:Play()
Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
BodyVelocity:Destroy()
Render:Disconnect()
end
Player.PlayerGui.GliderReady.Frame.Frame.UIGradient.Offset = Vector2.new(0, 0)
Player.PlayerGui.GliderReady.Frame.Frame.Transparency = 0.5
CoolDownImageTween:Play()
wait(120)
Player.PlayerGui.GliderReady.Frame.Frame.Transparency = 1
Player.PlayerGui.GliderReady.Frame.Frame.UIGradient.Offset = Vector2.new(0, 0)
GliderRE:FireServer()
CoolDown = true
StartGliderReady:Play()
wait(2)
EndGliderReady:Play()
end
end)