I’m trying to make R6 Legs face the Move Direction like in Evade
There is a Thread about it by Moodmonger but I’m not really into that CFrame stuff so it didn’t really help me.
I already converted a script in the Thread to R6 but its just spinning not following the direction you’re moving to
local LeftLeg = script.Parent:WaitForChild('Torso'):WaitForChild('Left Hip')
local RightLeg = script.Parent:WaitForChild('Torso'):WaitForChild('Right Hip')
local Angle = 0
local CenterOfLegs = Vector3.new(0,1,0)
while wait(.001) do
Angle += 0.1
LeftLeg.C0 = CFrame.new(CenterOfLegs) * CFrame.new(math.cos(Angle) * 0, 0, math.sin(Angle) * 0) * CFrame.Angles(0,-Angle,0)
RightLeg.C0 = CFrame.new(CenterOfLegs) * CFrame.new(math.cos(Angle + math.rad(180)) * 0, 0, math.sin(Angle+ math.rad(180)) * 0) * CFrame.Angles(0,-Angle - math.rad(180),0)
end
The problem is that it makes the legs go through the body and I don’t know how to fix that.
A:
A CFrame is just a 4x4 matrix that can represent rotation and translation.
A CFrame.new(position, point) is a constructor that will create a CFrame representing the rotation from point to position.
local myCFrame = CFrame.new(Vector3.new(0,0,0), Vector3.new(1,0,0))
print(myCFrame)
– CFrame: 0, 0, 0, 0.9999999, 0, 0, 0, 0, 1, 0, 0, 0
You can also use CFrame.Angles() to create a CFrame representing a rotation in euler angles.
local myCFrame = CFrame.Angles(math.rad(90), 0, 0)
print(myCFrame)
– CFrame: 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 1, 0
You can combine CFrame by using the * operator, like so:
local myCFrame = CFrame.new(Vector3.new(0,0,0), Vector3.new(1,0,0)) * CFrame.Angles(math.rad(90), 0, 0)
print(myCFrame)
– CFrame: 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 1
This means that if you have a CFrame like this
local myCFrame = CFrame.new(Vector3.new(1,0,0), Vector3.new(0,0,0)) * CFrame.Angles(0, 0, math.rad(90))
print(myCFrame)
– CFrame: 1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0, 1
It represents this rotation:
You can also use CFrame:LookAt(targetPos) to create a rotation that points from the origin of the CFrame to the target position.
local myCFrame = CFrame.new(Vector3.new(0,0,0), Vector3.new(1,0,0)):LookAt(Vector3.new(0,0,5))
print(myCFrame)
– CFrame: 0, 0, 0, 0, 0, 1, 0, 1, -0, 1, 0, 0
It’s important to note that constructing a CFrame like CFrame.new(centerPos, point) will create a rotation that points from the center position to the point. It’s not the same as CFrame.new(centerPos + point) which will create a CFrame with the center at centerPos + point, and the point at centerPos.
Now, to get to your code.
It looks like you’re trying to make the legs point in the same direction that the character is moving.
You can do this by creating a CFrame at the character’s root part, and pointing it in the direction that the character is moving:
local rootCFrame = script.Parent.HumanoidRootPart.CFrame
local moveDirection = rootCFrame.lookVector
local rotationCFrame = CFrame.new(rootCFrame.position, rootCFrame.position + moveDirection)
Now you can use that rotationCFrame to set the CFrame of your legs.
local leftLeg = script.Parent.Torso.LeftHip
local rightLeg = script.Parent.Torso.RightHip
local centerOfLegs = Vector3.new(0,1,0)
while wait(.001) do
leftLeg.C0 = rotationCFrame * CFrame.new(centerOfLegs)
rightLeg.C0 = rotationCFrame * CFrame.new(centerOfLegs)
end
Thanks that really helped me but the code you sent didn’t work it just made my legs C0 go far away
The Code above makes both of the Legs go in a circle around CenterOfLegs which is the Center of the Legs
local moveDirection = game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity.Unit
local moveDirectionRight = moveDirection * CFrame.new(0, 0, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)
local angleLeft = math.atan2(moveDirection.z, moveDirection.x)
local angleRight = math.atan2(moveDirectionRight.z, moveDirectionRight.x)
LeftLeg.C0 = CFrame.new(CenterOfLegs) * CFrame.fromEulerAnglesXYZ(0, angleLeft, 0)
RightLeg.C0 = CFrame.new(CenterOfLegs) * CFrame.fromEulerAnglesXYZ(0, angleRight, 0)
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.