Trying to rotate player and camera, but can't.

Easy problem, more difficult solution (for me anyways).

In my current dilemma, I am trying to jump into a teleporter and transport to another location. However, I don’t want to preserve the original camera or player’s rotation, I want it to change to a set value so the player is facing that direction when he goes through the teleporter.

For more information, here is my MouseLook script, and a section from PlayerController (Not Unity prefabs)
MouseLook

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour {

    public float sensitivity = 5f;
    private float xRotation;
    private float yRotation;
    [HideInInspector]
    public float xRotationCurrent;
    [HideInInspector]
    public float yRotationCurrent;
    private float xRotationVelocity;
    private float yRotationVelocity;
    public float lookSmoothDamp = 0.1f;
   
    void Awake() {
        Cursor.lockState = CursorLockMode.Locked;
    }
   
    void Update() {
        yRotation += (Input.GetAxis("Mouse X") * sensitivity);
        xRotation += (Input.GetAxis("Mouse Y") * -sensitivity);
        xRotation = Mathf.Clamp(xRotation, -90, 90);
        xRotationCurrent = Mathf.SmoothDamp(xRotationCurrent, xRotation, ref xRotationVelocity, lookSmoothDamp);
        yRotationCurrent = Mathf.SmoothDamp(yRotationCurrent, yRotation, ref yRotationVelocity, lookSmoothDamp);
        transform.rotation = Quaternion.Euler(xRotationCurrent, yRotationCurrent, 0);
       
        if (Input.GetKeyDown(KeyCode.Escape)) {
            Cursor.lockState = CursorLockMode.None;
        }
        if (Input.GetMouseButtonDown(0)) {
            Cursor.lockState = CursorLockMode.Locked;
        }
    }
}

PlayerController

void Walk() {
        transform.rotation = Quaternion.Euler(0, camera.GetComponent<MouseLook>().yRotationCurrent, 0);
        transform.Translate(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
        StartCoroutine(FootstepController(0.55f));
    }
   
    void Run() {
        transform.rotation = Quaternion.Euler(0, camera.GetComponent<MouseLook>().yRotationCurrent, 0);
        transform.Translate(Input.GetAxis("Horizontal") * walkAcceleration * sprintMultiplier, 0, Input.GetAxis("Vertical") * walkAcceleration * sprintMultiplier);
        StartCoroutine(FootstepController(0.3f));
    }

The problem is: when I enter the teleporter, my rotation is presumably changed, but it immediately reverts back to the original because Input.GetAxis is controlling the rotation value. Since I can not change this value to 0 via script (without adding custom scripts for Unity), does anyone see a fix? I am open to try anything. Let me know if you see something. Thank you.

When you set the players rotation after the teleport it changes back to the camera’s rotation because you need to set the camera’s rotation to be that rotation or it will remain the same as it was before the teleport.

I am assuming this as I don’t see your teleport code and how its setting the rotation.

Teleport code simply copies newObject.position and newObject.rotation to player.position/rotation. I will try this out ASAP

Update: did not work, presumably because of the reason stated above

Your MouseLook class holds the input value. When you change the rotation of the player you need to update both the yRotation and yRotationCurrent to be the same value in your MouseLook class. You wouldn’t need to update the player’s rotation as it will be updated by the MouseLook code.

This should work as MouseLook’s yRotation is the stored input value, hence the yRotation += Input.GetAxis(…
Changing both the yRotation and yRotationCurrent to the same value will avoid it being smoothed to the desired rotation.

I see what you are saying, I’ll try some things out regarding the current rotation and stored input. Thanks for the suggestion