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.
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)
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.
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.
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 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.