Hello, I want to make a system where i press E or Q and then the character leans to either the left or the right. I have the character in first person and i also want the camera to tilt to the right side as well. What would be the best way of doing this?
You could make animations tilting the torso and head for left and right respectively, and then play those animations depending on which key they’re pressing. This is for other people to see them tilt. For the player themselves, you can CFrame.Angles the Camera with tweenservice to make it look nice. Just ask if you need some code examples
Yeah, It would be good to see some examples for the first person camera. I know how to make an animation but I’m not sure how to apply it.
Alright, I’ve never done this before, so it was just a quick thought of how I would approach this.
I quickly made this and keep in mind, this does not work how you want it to work, but it’s a start. Look at the GIF to see how it works
local UIS = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local Camera = game.Workspace.CurrentCamera local Tilting = false local TweeningInformation = TweenInfo.new( .3, -- Length Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, -- Number of times the tween will repeat false, -- Should the tween repeat? 0 -- Delay between each tween ) local BeganBinds = { Q = function(object) --local TiltRight = Humanoid:LoadAnimation(script.Animation) --TiltRight:Play() if not Tilting then Camera.CameraType = Enum.CameraType.Scriptable Tilting = true local Goal = {CFrame = Camera.CFrame * CFrame.Angles(0,0,-25)} local Tween = TweenService:Create(Camera, TweeningInformation, Goal) Tween:Play() end end; E = function(object) --local TiltRight = Humanoid:LoadAnimation(script.Animation) --TiltRight:Play() if not Tilting then Camera.CameraType = Enum.CameraType.Scriptable Tilting = true local Goal = {CFrame = Camera.CFrame * CFrame.Angles(0,0,25)} local Tween = TweenService:Create(Camera, TweeningInformation, Goal) Tween:Play() end end; } EndedBinds ={ Q = function(object) --Stop Animation here local Goal = {CFrame = Camera.CFrame * CFrame.Angles(0,0,25)} local Tween = TweenService:Create(Camera, TweeningInformation, Goal) Tween:Play() Tween.Completed:Wait() Camera.CameraType = Enum.CameraType.Custom Tilting = false end; E = function(object) --Stop Animation here local Goal = {CFrame = Camera.CFrame * CFrame.Angles(0,0,-25)} local Tween = TweenService:Create(Camera, TweeningInformation, Goal) Tween:Play() Tween.Completed:Wait() Camera.CameraType = Enum.CameraType.Custom Tilting = false end; } UIS.InputBegan:Connect(function(object, processed) if not processed then if BeganBinds[object.KeyCode.Name] then BeganBinds[object.KeyCode.Name](object) end end end) UIS.InputEnded:Connect(function(object, processed) if not processed then if EndedBinds[object.KeyCode.Name] then EndedBinds[object.KeyCode.Name](object) end end end)
This is not the best way to do it, it’s buggy and it doesn’t work in first person. You would have to play the tilting animation, CFrame the Camera to the Character.Head.CFrame + the camera angle offset you want to simulate the tilt in a renderstepped loop. I hope this will help you get started