I have a part that moves with the character, and I’m attempting it to make it rotate in the direction that the player is walking. However, the issue can be seen in the video below:
And here is the code, which is binded to the render step:
local character = player.Character
local moveDirection = character.Humanoid.MoveDirection
local lookVector = character.HumanoidRootPart.CFrame.LookVector
local part = character.Part
local radius = part.Size.X * 0.5
-- Position the part at an offset from the player
local offsetVector = Vector3.new(lookVector.Unit.X, radius - 3, lookVector.Unit.Z)
part.Position = character.HumanoidRootPart.Position + lookVector.Unit * radius + offsetVector
-- Rotate the part in the direction the player is facing
local rotationAxis = lookVector:Cross(-Vector3.yAxis).Unit
part.CFrame *= CFrame.fromAxisAngle(rotationAxis, moveDirection.Magnitude/10)
The rotationAxis
is the orthogonal vector axis that the part should be rotating about, and I have confirmed this vector is correct and that the part, when testing, isn’t actually rotating about this vector axis.
I also tried re-orienting the part prior to rotating:
part.CFrame = CFrame.lookAt(part.Position, part.Position + lookVector)
But this seems to stop the rotation entirely.
So, is this an issue with how I’m applying the rotation transformation or is there something else I am missing?