Issues with CFrame:lookat()

I’m having issues with CFrame:lookat() that i’ve never encountered before, so I decided to come to here and share my issues.

Essentially, when using CFrame:lookat() it is freezing the player in place. If they try to move it lags them back. Here’s a video example;

External Media

(not sure why it makes u download :frowning: )
I’ve never ran into this issue before in all my time using lookat, and I’ve tried many other solutions. Is there something I’m missing, or…

(Forgot to include the code, lol)

rs.Heartbeat:Connect(function(t)
	if cameraSwitched == true then
		hrp.CFrame = CFrame.lookAt(hrp.Position, Vector3.new(enemyHRP.Position.X, hrp.Position.Y, enemyHRP.Position.Z))
	end
--disregard
	if blocking.Value == false then
		shield.Visible = false
	end
end)
3 Likes

I’m not familiar with this constructor but it seems as though it is affecting the CFrame’s positional values on a set standard, yet adjusting the CFrame’s rotational values differently. I can’t see it in the code you’ve provided so I’ll ask what exactly you are setting the “hrp” variable with/to?

1 Like

The HRP variable is the player’s HumanoidRootPart. I am attempting to make it rotate to the Enemies HumanoidRootPart (sorry if i did not make this clear). The rotation works, but the player is stuck in place for… some reason.

1 Like

My current working theory is that for some reason the players humanoid root part CFrame is not updated, therefore when you try to move the game think’s you’re still at your last spot and the new lookat CFrame sets it to where you were before.

1 Like

Yes that was my theory as well, try printing that hrp.Position every time the function fires to see if it changes at all.

1 Like

As you commented this I was just act to do this. The function prints the same position but an ever so slightly different rotation. (The rotation is slightly different even when neither of the HRP’s are moving).

Just out of curiosity, can you try setting a variable before running Cframe.lookat() and set the variable to the position prior to using the lookat(). Not sure why the position isn’t updating unless it is lagging behind because of the hrp variable.

For a reference, this is what I am trying to create;

A facing system like that.

1 Like

Tried this already, same result. I’m going to keep looking through any code that changes the HRP position and get back to you.

1 Like

I’d say that would have to be your problem, what happens if you add a very short task.wait() in there?

1 Like

You should not use cframe:lookat, use cframe.new instead

1 Like

Found no instances of other code tampering with the HumanoidRootPart position. Interestingly enough, putting it in a while task.wait(1) loop makes it work, but shortening that time makes it no longer work. I believe it is due to the HRP.Position variable not updating fast enough, therefore the player has to “backstep” a little bit. I’m not really sure how to fix this, and I think it may be more of a platform or script performance load issue.

1 Like

CFrame.new(pos, posToLookat) is deprecated. I will try it, but I am trying to avoid using deprecated functions

1 Like

Oh, I thought it was the other way around: CFrame.lookAt is deprecated and you have to use CFrame.new instead.

1 Like

No, unfortunately not. Either way, using CFrame.new still gives the same issue.

1 Like

CFrame.lookat is not deprecated according to the documentation.

2 Likes

It seems to almost be a sort of “Rubber band-ing” type of network delay issue, where the player sees themselves move before the server sees it.

1 Like

That seems to be the issue. I was going to toy with networkownership, but that doesn’t work either. I know there’s other games that do it and it works perfect, so I don’t see what I’m doing wrong (unless they use some other unknown method). It’s worth mention that :PivotTo worked only once when I tried it, then stopped rotating.

1 Like

You could maybe try some sort of modulescript placed in replicatedstorage that you can send the players positional data to?

2 Likes

That would only be slower, as then you have to handle transmitting and transferring data. I’m really lost here, maybe there’s some Roblox features I’m unaware of.

1 Like