You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? A camera tilt system like Apeirophobia.
What is the issue? I really can’t find anything on how to do it and I have no idea how I would do it either.
What solutions have you tried so far? I have looked all over dev forums and I want to try to do it on my own but I have no idea how.
Here is what I want to achieve: (with the thing where if you walk it titls too)
6 Likes
Qinrir
(Quin)
July 21, 2022, 9:54am
#2
What you gonna do is get acceleration
. I bet you know what that is. This is my theoretical script:
local Cam = workspace.CurrentCamera
local function GetRotationalCFrame(CFrame)
local x,y,z = CFrame:ToOrientation()
return Vector3.new(x,y,z)
end
local prevrotcf = GetRotationalCFrame(Cam.CFrame)
Cam.Changed:Connect(function()
local yacceleration = prevrotcf.Y-GetRotationalCFrame(Cam.CFrame).Y
-- set the cf I am not gonna do it cuz I am writing on devforum so its kinda hard.
end)
1 Like
2cola1
(2cola1)
July 21, 2022, 9:54am
#3
i may or may not have a script for this if you want it
1 Like
Yeah, that would be amazing. I have been looking for a few hours
1 Like
Yes, I know what it is, though I don’t know how to do the cf part.
1 Like
2cola1
(2cola1)
July 21, 2022, 9:59am
#6
gotta find it first
then test it if theres no bugs then there ya go
1 Like
Alright, you don’t know how much I appreciate this thank you
1 Like
Downrest
(Down)
July 21, 2022, 10:09am
#8
How do I add camera sway? - Help and Feedback / Scripting Support - DevForum | Roblox
You can use UserInputService:GetMouseDelta()
to get mouse delta, use the X direction of the mouse delta for camera turn.
here is a sample code I made
--Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
-- Variables
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Turn = 0
-- Functions
local Lerp = function(a, b, t)
return a + (b - a) * t
end;
-- Main
LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson -- First Person
RunService:BindToRenderStep("CameraSway", Enum.RenderPriority.Camera.Value + 1, function(deltaTime)
local MouseDelta = UserInputService:GetMouseDelta()
Turn = Lerp(Turn, math.clamp(MouseDelta.X, -6, 6), (15 * deltaTime))
Camera.CFrame = Camera.CFrame * CFrame.Angles(0, 0, math.rad(Turn))
end)
3 Likes
Thanks, though it feels really choppy. So idk.
1 Like
2cola1
(2cola1)
July 21, 2022, 10:22am
#10
there ya go
-- made by shade :/
wait(0.1)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Character = LocalPlayer.Character
if not Character then
Character = LocalPlayer.CharacterAdded:Wait()
end
local Humanoid = Character.Humanoid
local HumanoidRootPart = Character.HumanoidRootPart
local Camera = workspace.CurrentCamera
local Val = 0 -- this part may look ugly but it gets the job done
local Val2 = 0
local Val3 = 0
local Val4 = 0
local Val5 = 0
local Val6 = 0
local Int = 10
local Int2 = 10
local vector3 = Vector3.new()
lerp = function(a, b, c) -- i love lerp
return a + (b - a) * c
end
RunService.RenderStepped:Connect(function(DT)
DT = DT * 60
local magnitude = HumanoidRootPart and Vector3.new(HumanoidRootPart.Velocity.X, 0, HumanoidRootPart.Velocity.Z).Magnitude or 0
local magnitude2 = math.min(magnitude, 30)
if DT > 3 then
Val = 0
Val2 = 0
else
Val = lerp(Val, math.cos(tick() * 2 * math.random(10, 15)) * (math.random(5, 20) / 200) * DT, 0.05 * DT)
Val2 = lerp(Val2, math.cos(tick() * 2 * math.random(5, 10)) * (math.random(2, 10) / 200) * DT, 0.05 * DT)
end
Camera.CFrame = Camera.CFrame * (CFrame.fromEulerAnglesXYZ(0, 0, math.rad(Val3)) * CFrame.fromEulerAnglesXYZ(math.rad(Val4 * DT), math.rad(Val * DT), Val2) * CFrame.Angles(0, 0, math.rad(Val4 * DT * (magnitude2 / 5))) * CFrame.fromEulerAnglesXYZ(math.rad(Val), math.rad(Val2), math.rad(Val2 * 10)))
Val2 = math.clamp(lerp(Val2, -Camera.CFrame:VectorToObjectSpace((HumanoidRootPart and HumanoidRootPart.Velocity or Vector3.new()) / math.max(Humanoid.WalkSpeed, 0.01)).X * 0.08, 0.25 * DT), -0.25, 0.2)
Val3 = lerp(Val3, math.clamp(UserInputService:GetMouseDelta().X, -5, 5), 0.25 * DT)
Val4 = lerp(Val4, math.sin(tick() * Int) / 5 * math.min(1, Int2 / 10), 0.25 * DT)
if magnitude > 1 then
Val = lerp(Val, math.cos(tick() * 0.5 * math.floor(Int)) * (Int / 200), 0.25 * DT)
else
Val = lerp(Val, 0, 0.05 * DT)
end
if magnitude > 12 then
Int = 20
Int2 = 18
elseif magnitude > 0.1 then
Int = 12
Int2 = 14
else
Int2 = 0
end
vector3 = lerp(vector3, Camera.CFrame.LookVector, 0.125 * DT)
end)
4 Likes
2cola1:
-- made by shade :/
wait(0.1)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Character = LocalPlayer.Character
if not Character then
Character = LocalPlayer.CharacterAdded:Wait()
end
local Humanoid = Character.Humanoid
local HumanoidRootPart = Character.HumanoidRootPart
local Camera = workspace.CurrentCamera
local Val = 0 -- this part may look ugly but it gets the job done
local Val2 = 0
local Val3 = 0
local Val4 = 0
local Val5 = 0
local Val6 = 0
local Int = 10
local Int2 = 10
local vector3 = Vector3.new()
lerp = function(a, b, c) -- i love lerp
return a + (b - a) * c
end
RunService.RenderStepped:Connect(function(DT)
DT = DT * 60
local magnitude = HumanoidRootPart and Vector3.new(HumanoidRootPart.Velocity.X, 0, HumanoidRootPart.Velocity.Z).Magnitude or 0
local magnitude2 = math.min(magnitude, 30)
if DT > 3 then
Val = 0
Val2 = 0
else
Val = lerp(Val, math.cos(tick() * 2 * math.random(10, 15)) * (math.random(5, 20) / 200) * DT, 0.05 * DT)
Val2 = lerp(Val2, math.cos(tick() * 2 * math.random(5, 10)) * (math.random(2, 10) / 200) * DT, 0.05 * DT)
end
Camera.CFrame = Camera.CFrame * (CFrame.fromEulerAnglesXYZ(0, 0, math.rad(Val3)) * CFrame.fromEulerAnglesXYZ(math.rad(Val4 * DT), math.rad(Val * DT), Val2) * CFrame.Angles(0, 0, math.rad(Val4 * DT * (magnitude2 / 5))) * CFrame.fromEulerAnglesXYZ(math.rad(Val), math.rad(Val2), math.rad(Val2 * 10)))
Val2 = math.clamp(lerp(Val2, -Camera.CFrame:VectorToObjectSpace((HumanoidRootPart and HumanoidRootPart.Velocity or Vector3.new()) / math.max(Humanoid.WalkSpeed, 0.01)).X * 0.08, 0.25 * DT), -0.25, 0.2)
Val3 = lerp(Val3, math.clamp(UserInputService:GetMouseDelta().X, -5, 5), 0.25 * DT)
Val4 = lerp(Val4, math.sin(tick() * Int) / 5 * math.min(1, Int2 / 10), 0.25 * DT)
if magnitude > 1 then
Val = lerp(Val, math.cos(tick() * 0.5 * math.floor(Int)) * (Int / 200), 0.25 * DT)
else
Val = lerp(Val, 0, 0.05 * DT)
end
if magnitude > 12 then
Int = 20
Int2 = 18
elseif magnitude > 0.1 then
Int = 12
Int2 = 14
else
Int2 = 0
end
vector3 = lerp(vector3, Camera.CFrame.LookVector, 0.125 * DT)
end)
It works! Also is smooth and satisfying. Thank you so much!
3 Likes
variables all over the place…
Looks decompiled
1 Like
2cola1
(2cola1)
July 21, 2022, 9:06pm
#13
my friend said the same thing eariler when he wanted a better camera bob
DevChams
(Chams)
July 29, 2022, 11:37am
#14
This is very good although, for me it shakes alot when i’m standing still, does that happen to you?
Do you know why this happens, what the variables for it is or anything that causes this.
blockleman
(blockleman)
July 30, 2022, 12:55pm
#15
no he does not know (because it’s decompiled) but I am guessing it’s from when magnitude
is less than 1, so Val
(funny name for a variable right) gets lerped with deltaTime etc
3 Likes
DevChams
(Chams)
July 30, 2022, 12:57pm
#16
I found that out aswel, script looked kinda suspicious too. Thanks
2cola1
(2cola1)
August 1, 2022, 3:05am
#17
it’s not decompiled???
dont know where you got that from.
anthlons
(tatemcraefan45)
August 1, 2022, 4:08am
#18
Maybe because this entire line of (decompiled) code is nearly 1:1 to yours except for a few variable names? Don’t steal code and claim it as your own.
7 Likes
To add on, if it wasn’t decompiled they should know what variables mean not just to be “trusted” with them.
I could be wrong here, but yeah.
2 Likes
anthlons
(tatemcraefan45)
August 1, 2022, 6:06pm
#21
Went into the game and decompiled it myself, just as you did, except you took credit for the making of the code.
6 Likes