my idea of gui swaying is not very reliable how do i fix the bounciness?
the first idea i had was to make a stationary point/attachment infront of the head and the gui would be updated constantly in a loop to that position. i know its a wacky solution but im not good with reading math
head bob and yes i did took it from someone
003 | local OFFSET = Vector 3. new( 0 , 3 , 0 ) |
004 | local RAY_DISTANCE = 100 |
006 | local SENSITIVITY = 0.006 |
008 | local UPPER_ANGLE_LIMIT = math.rad( 85 ) |
009 | local LOWER_ANGLE_LIMIT = math.rad(- 85 ) |
011 | local BOB_FREQUENCY_Y = 4 |
012 | local BOB_FREQUENCY_X = 2 |
015 | local BOB_AMPLITUDE_X = 0.6 |
016 | local BOB_AMPLITUDE_Y = 0.4 |
018 | local MAX_VELOCITY = 16 |
020 | local RECENTER_SPEED = 4 |
022 | local RunService = game:GetService( "RunService" ) |
023 | local Players = game:GetService( "Players" ) |
024 | local UserInputService = game:GetService( "UserInputService" ) |
026 | local localPlayer = Players.LocalPlayer |
027 | local character = localPlayer.Character or localPlayer.CharacterAdded:Wait() |
028 | local currentCamera = workspace.CurrentCamera |
030 | local Rot = CFrame.new() |
031 | local Tilt = CFrame.new() |
033 | local cameraAngle = Vector 2. new( 0 , 0 ) |
035 | local velocityMultiplier = 0 |
038 | local function GetRollAngle() |
039 | local Character = localPlayer.Character |
041 | if not Character then |
045 | local Cf = currentCamera.CFrame |
047 | return -Cf.RightVector:Dot(Character.Humanoid.MoveDirection) |
049 | local function scalarLerp(a, b, c) |
050 | c = math.clamp(c, 0 , 1 ) |
051 | return a + c * (b - a) |
054 | function MouseRay(filterTable, filterType, mousePosition) |
056 | local rayData = currentCamera:ScreenPointToRay(mousePosition.X, mousePosition.Y, 0 ) |
058 | local raycastParams = RaycastParams.new() |
059 | raycastParams.FilterDescendantsInstances = filterTable |
060 | raycastParams.FilterType = filterType |
062 | return workspace:Raycast(rayData.Origin, rayData.Direction * RAY_DISTANCE, raycastParams) |
064 | local function InitOffsetAttachment(Char) |
065 | local Attachment = Instance.new( "Attachment" ) |
066 | Attachment.Name = "OFFSET" |
067 | Attachment.Parent = character:WaitForChild( "HumanoidRootPart" ) |
068 | Attachment.WorldPosition = character:WaitForChild( "Head" ).Position |
069 | return Attachment.Position |
071 | local function MakeBodyVisible(Char,Match) |
072 | for _,v in pairs (Char:GetDescendants()) do |
073 | if v:IsA( "BasePart" ) then |
074 | v.LocalTransparencyModifier = 1 |
078 | local function renderStepped(deltaTime) |
079 | local humanoidRootPart = character:FindFirstChild( "HumanoidRootPart" ) |
080 | local mouseDelta = UserInputService:GetMouseDelta() * SENSITIVITY |
081 | local MouseDeltaX = UserInputService:GetMouseDelta().X |
083 | currentTime + = deltaTime |
084 | local bobOffsetY = (math.sin(currentTime * math.pi * BOB_FREQUENCY_Y) - 0.5 ) * BOB_AMPLITUDE_Y |
085 | local bobOffsetX = (math.sin(currentTime * math.pi * BOB_FREQUENCY_X) - 0.5 ) * BOB_AMPLITUDE_X |
087 | local velocityMagnitude = (humanoidRootPart.Velocity * Vector 3. new( 1 , 0 , 1 )).Magnitude |
088 | local targetVelocityMultiplier = math.clamp(velocityMagnitude, 0 , MAX_VELOCITY) / MAX_VELOCITY |
089 | velocityMultiplier = scalarLerp(velocityMultiplier, targetVelocityMultiplier, RECENTER_SPEED * deltaTime) |
090 | bobOffsetX * = velocityMultiplier |
091 | bobOffsetY * = velocityMultiplier |
093 | cameraAngle - = mouseDelta |
094 | cameraAngle = Vector 2. new( |
096 | math.clamp(cameraAngle.Y, LOWER_ANGLE_LIMIT, UPPER_ANGLE_LIMIT) |
099 | local Roll = GetRollAngle() * 4 |
100 | Rot = Rot:Lerp(CFrame.Angles( 0 , 0 , rad(Roll)), 0.075 ) |
101 | localPlayer.Character:WaitForChild( "Humanoid" ).AutoRotate = false |
102 | local RootPos, MousePos = humanoidRootPart.Position, localPlayer:GetMouse().Hit.Position |
103 | humanoidRootPart.CFrame = CFrame.new(RootPos, Vector 3. new(MousePos.X, RootPos.Y, MousePos.Z)) |
104 | Tilt = Tilt:Lerp(CFrame.Angles( 0 , 0 , rad(math.clamp(math.round(MouseDeltaX),-MaxTilt,MaxTilt)), 0 ), 0.075 ) |
105 | currentCamera.CFrame = |
106 | CFrame.new(humanoidRootPart.Position+OFFSET) * CFrame.new( 0 , bobOffsetY, 0 ) * |
107 | CFrame.Angles( 0 , cameraAngle.X, 0 ) * |
108 | CFrame.Angles(cameraAngle.Y, 0 , 0 ) * |
109 | CFrame.new(bobOffsetX, 0 , 0 ) * (Rot * Tilt) |
111 | RunService.RenderStepped:Connect(renderStepped) |
112 | OFFSET = InitOffsetAttachment(character) |
and heres my prototype ik its very ugly
01 | local runS = game:GetService( "RunService" ) |
02 | local Cam = workspace.CurrentCamera |
03 | local LocalPlayer = game:GetService( "Players" ).LocalPlayer.Character:WaitForChild( "Head" ):WaitForChild( "FaceFrontAttachment" ) |
04 | local Frame = game:GetService( "Players" ).LocalPlayer.PlayerGui.ScreenGui.Frame |
05 | local function SetupAttachment(Char) |
06 | local A = Instance.new( "Attachment" ) |
07 | A.Parent = Char:WaitForChild( "HumanoidRootPart" ) |
08 | A.WorldPosition = Char:WaitForChild( "Head" ).Position + Char:WaitForChild( "Head" ).CFrame.LookVector |
11 | local Attachment = SetupAttachment(game:GetService( "Players" ).LocalPlayer.Character) |
12 | runS.Stepped:Connect( function () |
13 | Frame.Position = UDim 2. fromOffset(Cam:WorldToViewportPoint(Attachment.WorldPosition).X,Cam:WorldToViewportPoint(Attachment.WorldPosition).Y) |