I’m making a custom character engine, and I’ve been having issues with the player’s rotation for all of the time I’ve been working on this game.
I need to get the player to rotate towards their MoveDirection, and I’ve tried everything to accomplish that - with limited success - since I relied on the unreliable AlignOrientation constraint; the contraint is good on paper but bad in practice, as you can’t control the player’s turning speed very well.
I tried to use CFrames because of this, they allow for more control over the turning speed of the player. However, in my experiences, they make me violently angry and evil the way they cause the player to seize the moment the lay a finger on an incline.
BETTER YET just existing in the first place causes the player to tear reality to shreds like a wet piece of paper; see for yourself ![]()
here’s my poorly written code.
function phys.GroundCheck(self)
local oldCFrame
rs.RenderStepped:Connect(function(dt)
local ray = rayfuncts.DownRay(self)
local orentation
if ray == nil or self.jump_Request == true then
local MD_Rot = CFrame.lookAt(self.hrp.Position, self.hrp.Position + Vector3.new(self.move_Direction.Unit.X, 0, self.move_Direction.Unit.Z))
rayfuncts.visualizeRay(self.hrp.Position, self.hrp.Position + Vector3.new(0, -self.humanoid.HipHeight, 0), Color3.fromRGB(0, 0, 255))
if self.move_Direction ~= Vector3.zero then
orentation = CFrame.lookAt(self.hrp.Position, self.hrp.Position + self.hrp.CFrame.LookVector)
else
orentation = CFrame.lookAt(self.hrp.Position, self.hrp.Position + self.hrp.CFrame.LookVector)
end
self.hrp.AssemblyAngularVelocity = Vector3.zero
self.hrp.CFrame = orentation
self.alignPosition.Enabled = false
self.grounded = false
return
end
if ray ~= nil and self.jump_Request == false then
self.grounded = true
oldCFrame = self.hrp.CFrame
local offset = self.humanoid.HipHeight
local hitNormal = ray.Normal
local currentRightVector = self.hrp.CFrame.RightVector
local upVector = hitNormal
local newFacialVector = self.move_Direction
local Rot = CFrame.fromMatrix(self.hrp.Position, currentRightVector, upVector, newFacialVector) + self.hrp.Position
local appliedRot:CFrame = CFrame.lookAt(self.hrp.Position, self.hrp.Position + Vector3.new(self.move_Direction.Unit.X, 0, self.move_Direction.Unit.Z))
self.angle = math.deg(math.acos(hitNormal:Dot(Vector3.zAxis)))
self.normal = ray.Normal
self.material = ray.Material
self.alignPosition.Enabled = true
self.alignPosition.Position = ray.Position + self.hrp.CFrame.UpVector * offset
self.hrp.AssemblyAngularVelocity = Vector3.zero
if self.humanoid.MoveDirection ~= Vector3.zero and self.state ~= 5 and not (self.state == 2 and self.sub_State == 1) then
self.hrp.CFrame = self.hrp.CFrame:Lerp(CFrame.lookAt(self.hrp.Position, self.hrp.Position + Vector3.new(self.humanoid.MoveDirection.X, 0, self.humanoid.MoveDirection.Unit.Z)), self.turn_speed)
elseif (self.state == 2 and self.sub_State == 1) or self.state == 5 then
self.hrp.CFrame = CFrame.lookAt(self.hrp.Position, self.hrp.Position + self.hrp.CFrame.LookVector)
else
self.hrp.CFrame = CFrame.lookAt(self.hrp.Position, self.hrp.Position + self.hrp.CFrame.LookVector)
end
rayfuncts.visualizeRay(self.hrp.Position, ray.Position, Color3.fromRGB(255,0,0))
end
end)
end
I’ve tried and tried and TRIED to get this stupid player rotation under control but I JUST CAN T FIGURE I TOUT IU CANT I CAN T IC CANT HELP HELP EHLPE HPEL
I’ll add more to this post later, I’m writing this down in a rush
Thanks in advance!