I’ve been trying to figure out how to rotate my player character in my FPS. In it, the camera moves as you move the mouse. For that, I use this code:
void Update()
{
if (gm.canMove == true && gm.inDialogue == false)
{
GetInput();
ModifyInput();
MovePlayer();
}
}
float calculateSensitivity()
{
float sens = settings.lookSensitivity;
sens *= 2;
if (sens <= 0f)
{
sens = 0.1f;
}
return sens;
}
void MovePlayer()
{
currentLookingPos += smoothMousePos;
transform.localRotation = Quaternion.AngleAxis(currentLookingPos, transform.up);
}
void ModifyInput()
{
xMousePos *= (sensitivity * calculateSensitivity()) * smoothing;
smoothMousePos = Mathf.Lerp(smoothMousePos, xMousePos, 1f/smoothing);
}
Now, what I’m trying to do is when the player triggers something, I “teleport” them to a new location using just transform.position = tpLocation.transform.position
. (which I needed to enable Auto Sync Transforms
in Physics
to get to work). However, if I just do this, it leaves them facing a wall. So I need to rotate them. I’ve looked up how I could do it, but none of them seem to be working. Nothing happens. It is like the Mouse is overriding it immediately so nothing changes and they look in the same direction.
I’ve tried player.transform.Rotate
, player.transform.rotation
with EulerAngles
, and also doing it how I did in MouseLook
with the localRotation
and AngleAxis
. None of that has worked.
Ah, by the way, my Character consists of the player with a Character Controller
and the Camera
is attached to them. That’s the only two things that might matter here. The rest is just code or mesh renderers. I don’t have any rigid bodies on it.
Any ideas?