Hey
I’m new to scripting and I’m trying to make a leaning emote in a personal project i’m working on
Does anyone know how to make a transition from a stand to a lean on the side like this? image belownot mine
I’ve tried tutorials on YouTube but I can’t seem to find what I’m looking for.
In detail, I’d like it so if you press a specific key on the keyboard, the upper part of the character leans to the right, just like the image above. The player camera should also rotate as much as the character does. I’m not sure how to work this 'cus I’m completely new to scripting and stuff, so help is appreciated
Try creating a leaning left/right animation using the Roblox animation editor (make the animation looped.) Once the player hits a key (UserInputService), play that animation using Humanoid:LoadAnimation()
Yup, I’m pretty sure this script covers that, now i’lI just need to figure out how to rotate the Users Camera as well local
UI = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local Run = false
UI.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Left then
if not Run then
Run = true
Animation:Play()
Humanoid.WalkSpeed = 9
else
Animation:Stop()
Run = false
Humanoid.WalkSpeed = 9
end
end
end)
Try setting the camera subject to the head during the animation. (Inside the same script)
local camera = workspace.CurrentCamera
-- when you play the animation do this:
camera.CameraSubject = script.Parent:WaitForChild("Head")
-- when you stop the animation do this:
camera.CameraSubject = Humanoid
With this, no complicated CFrame math is required.
We simply set the subject of the main camera to the head so that it follows the head position instead of the HumanoidRootPart position. Then we reset it after the animation ends.
Also, I recommend you turn “UI” into “local UI”. Localizing variables and services improves game performance.