How would you make a character's torso face in a certain direction?

Hi! :smile:
How can you make the character’s hands and torso face in a custom direction, like, for example, towards the mouse cursor, like it was in Jailbreak when you hold out a gun? I looked in different places, but I unfortunately can’t find any info on how to customly position only the character’s torso or hands, nor can I find a working example :frowning:

I obviously don’t want someone to write the entire system for me, that would be stupid, I just wan’t to know what element of Roblox can I use to customly rotate a player’s torso, and develop the system using it myself.

Notes: I know how to animate and play animations, if that can help

Thanks in advance, Mun :smile:

EDIT: you need to lock the mouse for mouse delta to work. Enable mouse lock through userinputservice. If you need this to work with a free 3rd person camera, instead of editing X and Y by delta every frame just get the mouse position relative to the center i.e. userinputservice:getmouselocation - (workspace.CurrentCamera.ViewportSize/2)

There’s two options here: either you want it to replicate to the server or you don’t. The second option is far easier. What you should do is update the Transform of the waist joint of the character every render step. If you want all players to see the player turning, you’ll have to send info to the server about the player turning, then the server will modify the player’s torso turning.

Other than that, in both cases the code is very similar. You can use something like UserInputService:GetMouseDelta() to see how much the mouse is moving every frame, and use the X movement to facilitate Y rotation, and vice versa. Then, you should use the Stepped event of RunService (might not work properly with heartbeat or renderstep!) to update the waist transform every frame. You have to update it every frame because otherwise it’ll risk being overridden by other playing animations. The nice side to this is when you stop updating the transform i.e. the player unequips the weapon, the character rig will smoothly transition back to its typical animations.

Example code (client):

--represents the ROTATION, not the movement
local X = 0
local Y = 0
local xMin, xMax, yMin, yMax, sens = -75,75,-30,30, 0.1 --play around with these!
local Waist = game.Players.LocalPlayer.Character.UpperTorso.Waist
local UserInputService = game:GetService("UserInputService")
local rad = math.rad


--youll want to store this connection as a variable in actual code as you need to be able to toggle the updating
game:GetService("RunService").Stepped:Connect()
local delta = UserInputService:GetMouseDelta()*sens
X = math.clamp(X + delta.Y, xMin, xMax)
Y = math.clamp(Y + delta.X, yMin, yMax)
Waist.Transform = CFrame.Angles(rad(X), rad(Y), 0)
end)

Not too complicated. If you want to replicate it you just send X and Y via a remote event (though probably not every frame) and set transform on server side.

3 Likes

Thanks a lot for the explaination and the script! You didn’t really have to write that for me :smile: … Although, I did not understand what Waist.Transform does…
I did not understand the api-reference :frowning:

1 Like