In the video my character is not moving as fast as he should. This is because i set the Characters Rotation everytime the LookVector it exceeds a certain amount and when he changes direction. This makes sure that the character is always looking Left or Right perfectly.
The only problem is my character keeps getting its position set every :RenderStepped(). How do i set the Rotational CFrame without the position??
My code:
local function CameraStepped()
print(HumanoidRootPart.CFrame.LookVector.X)
if leftValue == 1 then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Vector3.new(-90,0,0))
end
if HumanoidRootPart.CFrame.LookVector.X > -0.95 and HumanoidRootPart.CFrame.LookVector.X < 0 then
--///Turn Left
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Vector3.new(-90,0,0))
end
if HumanoidRootPart.CFrame.LookVector.X < 0.95 and HumanoidRootPart.CFrame.LookVector.X > 0 then
--///Turn Right
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Vector3.new(90,0,0))
end
if rightValue == 1 then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position, Vector3.new(90,0,0))
end
end
````
This is probably happening because you introduced a wrong value. CFrame.Angles accepts values in radians. If you put a big number (eg 90), the resulting LookVector will most likely be smaller than 0.95 and bigger than -0.95, forcing the character to rotate every frame.
Try using something like CFrame.Angles(0, .5*math.pi, 0)
I recommend not setting the CFrame/rotation, but letting the character move on its own. You can override the default humanoid movement and manually use Move to make the character move. To do this, get input from the a and d keys and move the character only to the left or right.
If you are worried about something pushing the character off the edge, you can try using a constraint or maybe an old body mover if you have to.
There should be a tutorial somewhere with more details on how to do this.
Also, if you don’t want to change the code you have, you can rotate the character with constraints or maybe body movers.