Hello developers, I am trying to rotate the players “RootJoint” only on one single Axis. Currently this is my line
.
I am getting no errors at all could somebody help?
Or if there’s a way to get all vectors and remove them anything that would make it rotate on one vector would help.
This will rotate it around its x-axis as long as rotationAngleInRadians
is set.
hrp.RootJoint.C0 *= CFrame.Angles(rotationAngleInRadians, 0, 0)
If you want to rotate it around the x-Axis of HumanoidRootPart, change the order of the CFrames in the multiplication, calculate the new orientation using only the rotation matrix of the original C0
and apply the position in the end.
hrp.RootJoint.C0 = CFrame.Angles(rotationAngleInRadians, 0, 0) * hrp.RootJoint.C0.Rotation + hrp.RootJoint.C0.Position
The position needs to be removed initially because when a CFrame
containing a non-zero position is on the right side of the multiplication, this position and the CFrame
on the left side will determine the position of the result of the multiplication.
When the CFrame on the right has the zero vector as its position vector, the position of the multiplication result is just the position of the CFrame
on the left.
So, when rotating around hrp x-axis, if we first calculate the orientation and then apply the position, the new C0 will have the original position but a new rotation.
I’ve had this exact issue yesterday.
This example is changing the C0’s Z axis orientation.
Feel free to look:
I used CFrame.fromOrientation()
to change that, and i then used math.rad()
for the numbers.
example.CFrame *= CFrame.fromOrientation(0,0,math.rad(90))
--You must use math.rad() for the numbers.
--Except if the number is 0.
This doesn’t seem to work at least on C0’s
Can you explain to me what rotationAngleInRadians is? The script does not recognize it.
You see, roblox uses radians instead of degrees in the rotations. To convert degrees to radians use math.rad(degrees)
.
Try this.
hrp.RootJoint.C0 *= CFrame.Angles(math.rad(headrot.XVector), 0, 0)
math.rad
is mean for converting an angle defined in degrees to an angle defined in radians. You are not giving it an angle in your code. You are giving it a direction vector. If you had a vector that contains angles defined in degrees (for example BasePart.Orientation), you can convert it to a vector containing radian angles using either of the following two ways:
local angleVectorInRadians = Vector3.new(math.rad(angleVectorInDegrees.X), math.rad(angleVectorInDegrees.Y), math.rad(angleVectorInDegrees.Z))
local angleVectorInRadians = angleVectorInDegrees * math.pi / 180
However, the components of a cartesian direction vector like CFrame.XVector
are not angles.
@WADSCOOOll , here’s an example of rotating the C0
35 degrees around its x-axis.
local rotationAngleInDegrees = 35
local rotationAngleInRadians = math.rad(rotationAngleInDegrees) -- equal to rotationAngleInDegrees * math.pi / 180
hrp.RootJoint.C0 *= CFrame.Angles(rotationAngleInRadians, 0, 0)
I know math.rad
accepts only degrees. But he was intentionally trying that rotate with that headrot.XVector
. I’m not responsible for the unceirtanty that his variables brought, all I did is provide a solution.
Well, yes. His code doesn’t do the intended thing either (it changes the position of hrp.RootJoint.C0 and not the rotation). However, instead of editing non-working code into code that doesn’t work either and even gives an error, I think it would be a better idea to write code that works, or, if the goal is unclear, ask for clarification.
Speaking of asking for clarification, I actually started to think that the code I gave earlier doesn’t solve this either (doesn’t rotate around the correct axis). So, @WADSCOOOll , what is headRot
? Is it the CFrame of the character’s head or something else? When writing my code, I didn’t realise you were trying to rotate the joint between HumanoidRootPart and Torso using a vector somehow related to head. Thus, rotating around the x-axis of the current C0 or the torso x-axis (things that my code do) probably aren’t what you want. Instead, CFrame.fromAxisAngle
might be useful because it can be used for rotating around any vector. But before I try to write code using it, I’d like to know what headRot
is.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.