I’m making a game with a target lock, where I want the character to face the other player’s character. However, when I try rotating the character, the character rotates but I can’t move. Any help here?
Video of the issue: Video
My code:
function ClassModule:TurnCharacter(target)
--print("SIR")
local root = self.Character.HumanoidRootPart
root.CFrame = CFrame.new(root.Position,target.HumanoidRootPart.Position)
end
Yeah I think it does that because it constantly sets both your position and your orientation. While it does set the position the root’s current position, due to lag, it actually ends up setting your position back in time just a tad and as a result you get stuck in place.
I think Limited_Unique is right in the sense that you would want to use just the orientation, but clearly you’re using the CFrames to actually get the orientation in the first place, so here’s what I would do:
First of all, CFrame.new(pos, lookAt) has been replaced with CFrame.lookAt(pos, lookAt):
Now since we just want to change the orientation, rather than setting root.CFrame = CFrame.new(pos, lookAt), we can take the XYZ orientation of the CFrame using :ToOrientation():
local root = self.Character.HumanoidRootPart
local x, y, z = CFrame.lookAt(root.Position, target.HumanoidRootPart.Position):ToOrientation()
root.Orientation = Vector3.new(x, y, z)
I have heard, however, that :ToOrientation() isn’t 100% accurate and is just an approximation so I’m not really sure if that’d be an issue or not.
You’re setting the .Orientation and nothing else right? If that’s all you’re changing and it’s still changing your pos it would have to be a problem somewhere else I would think.
function ClassModule:TurnCharacter(target)
--print("SIR")
local root = self.Character.HumanoidRootPart
local x,y,z = CFrame.lookAt(root.Position,target.HumanoidRootPart.Position):ToOrientation()
root.Orientation = Vector3.new(x,y,z)
end
See what happens if you just don’t run it at all. That way we can know if it’s something else at fault. If not running it at all makes so you can move again, then maybe try what GolgiToad suggested with BodyGyros.
I’ve switched it off and nothing happened, I could move around. I am hesitant to use BodyGyros though because according to the wiki, they really shouldn’t be used anymore.
Hm, you’re right. Instead it says to use AngularOrientation, but the link doesn’t lead anywhere and I can’t find anywhere that says what that is. I recently used BodyGyros in a wall climbing script though and I had no issues with it.
I am making a rooms fangame and have the same exact problem. The player jerks back when i turn with a camera script. Maybe write down the velocity, turn, and add the velocity to the position?