How do I make a directional movement? (rotating the torso or limbs)

I want to do a directional movement that when you go right or left it rotates the limbs. I have seen a lot of videos with this movement type/script but I couldn’t find any way, forum post or a tutorial to know how to make it. I just don’t know where to start. I’m not thinking of doing procedural or 4 different animations.

Example videos:

1 Like

For this you can use humanoidrootpart velocity

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character.HumanoidRootPart
local Torso = Character.Torso

local RootJoint = HumanoidRootPart.RootJoint
local LeftHipJoint = Torso["Left Hip"]
local RightHipJoint = Torso["Right Hip"]

--Lerp
local function Lerp(a, b, c)
	return a + (b - a) * c
end
local Force = nil
local Direction = nil
local Value1 = 0
local Value2 = 0

local RootJointC0 = RootJoint.C0
local LeftHipJointC0 = LeftHipJoint.C0
local RightHipJointC0 = RightHipJoint.C0

RunService.RenderStepped:Connect(function()
	-- To get the force, we multiply the velocity by 1,0,1, we don't want the Y value so we set y to 0
	Force = HumanoidRootPart.Velocity * Vector3.new(1,0,1)
	if Force.Magnitude > 0.001 then
		-- This represents the direction
		Direction = Force.Unit	
		Value1 = HumanoidRootPart.CFrame.RightVector:Dot(Direction)
		Value2 = HumanoidRootPart.CFrame.LookVector:Dot(Direction)
	else
		Value1 = 0
		Value2 = 0
	end
RootJoint.C0 = RootJoint.C0:Lerp(RootJointC0 * CFrame.Angles(math.rad(Value2 * 14), math.rad(-Value1 * 22), 0), 0.2)
	LeftHipJoint.C0 = LeftHipJoint.C0:Lerp(LeftHipJointC0 * CFrame.Angles(math.rad(Value1 * 10), 0, 0), 0.2)
	RightHipJoint.C0 = RightHipJoint.C0:Lerp(RightHipJointC0 * CFrame.Angles(math.rad(-Value1 * 10), 0, 0), 0.2)
end)

I begginer in roblox if i have errors you can fix

2 Likes

Sorry for not being clear. I asked for how to do a directional movement that when you press A while you shiftlocked your limbs or torso ROTATES/TURNS to left. I’m not asking for how to do a LEANING script.

ahh sorry, but this leaning you can transform to your idea

A few days ago I tried changing a leaning script to movement but it didn’t work. Thanks for your help though.

ok but i will try to write the script you need because i want to really help you

I just wanted to get to know where to start scripting it but it’s up to you if you want to do it.

Here it is: Directional Movement + Strafing / Tilting - Roblox

One way to achieve directional movement in Roblox without using procedural or multiple animations is by using inverse kinematics (IK). IK is a method for calculating joint positions based on a desired end-effector position, such as the position of a character’s foot.

To implement IK-based movement, you would need to define a set of target positions for each limb in your character model. These target positions would depend on the direction of movement. For example, if the character is moving to the right, the target position for the left arm would be slightly behind the character, while the target position for the right arm would be slightly in front of the character.

You would then use an IK solver to calculate the joint angles needed to reach each target position. This would result in the limbs rotating appropriately to match the desired movement direction.

There are several IK solvers available in Roblox, including the HumanoidIK class, which can be used to manipulate a character’s limbs using IK.

Keep in mind that IK-based movement can be more complex to implement than other methods.

2 Likes

As I saw some examples of IK, it makes animations look more physics based. But will it be a problem if I add some non-IK action animations like a weapon attack or a normal jump animation?

I’ve tried IK before, For example in my game theres a sprint animation; and instead of animating the legs when sprinting (with IK) the legs will act as if I’m still walking instead.

May be due to the way i applied inverse kinematics - But it hasn’t worked for me.

I forgot about this post.

I achieved it without IK. It was actually a basic thing to do with lerping and some little confusing math (for me). To anyone who wants to make it should do it with lerp, I don’t recommend Tweening because it will break after a while whenever you want to upgrade your script. No need for IK, expect if you want legs-stairs moving thing.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.