Im trying to rotate the character by using my mouse for a custom movement script, but I am getting issues. Im not sure if there is a better way to rotate a player, this is the code I came up with:
The character freezes in place, which I know is because im basically telling it to stay stuck to the position of the head, but I dont know a workaround this, that allows the player to move yet still rotate, as I have to continuously update this line in RunService to keep the mouse position updated.
wont I still have to multiply this to Cframe.new()?
I did that because i thought Cframe = position of part * rotation of part, so if i want to change a part’s cframe I have to write the position first, then the rotation, which i want to edit, after
and would that stop the character from being stuck in place?
the code I have is ran through run service, so if there was any way to NOT have to reference position every time that would be helpful
i mean im pivoting my character by using cframe of course, but because i have to reference the position, it keeps the character stuck in place, as i am running this line of code under runservice. So it would look like this:
CFrame is a unmutable value, once it created it cannot be changed , i dont understand what you are trying to archive?
You need to reindex it every time obviously to get most uptodate CFrame
im pivoting my character (a model) to a cframe, I only want to change the angle the character is facing (x rotation of character model) so Im trying to find a way to do that. Thing is, i have to reference the position and rotation, which is causing the character to stay in place as the cframe is sending a position and rotation, but i only want to send rotation, so im asking how to do that.
char:PivotTo(char.HumanoidRootPart.CFrame*CFrame.Angles())
You should probably use physics constraint or character controller? for this kind of shenanigans anyway
Try using this code, which rotates the whole character using the (mouseX, HumanoidRootPart_Y, mouseZ) rotation through CFrame.lookAt().
RunService:BindToRenderStep("ShoulderCamera", Enum.RenderPriority.Character.Value, function()
local mouseX = Mouse.Hit.Position.X -- Attain mouse's X position in 3D space
local mouseZ = Mouse.Hit.Position.Z -- Attain mouse's Z position in 3D space
-- We only got the "y" component of the humanoidrootpart since we don't want the player to fly.
local HumanoidRootPart_Y = HumanoidRootPart.Position.Y
local lookCFrame = CFrame.lookAt(HumanoidRootPart.Position, Vector3.new(mouseX, HumanoidRootPart_Y , mouseZ))
HumanoidRootPart.CFrame = HumanoidRootPart.CFrame:Lerp(lookCFrame, .25)
-- You may modify the "alpha time" of the lerp that suits your needs.
end)
However, I am unsure if this solves your problem, but I hope it does based on the information you gave about the mouse rotating the character. You’re welcome!
ok guys i realize what my problem is. I was trying to rotate the player on the server, but the server was only getting the player’s inital position instead of its true current position, so it would make the player seem like they were stuck. Thank you guys all for helping though!