I use character controller for my player and at first it walks fine but after I make him rotate his body to face the direction he’s going to he starts walking and turning really weird
See the video here: Reddit - Dive into anything
public class PlayerMovement : MonoBehaviour{
public static PlayerMovement Player;
[SerializeField]
public float _moveSpeed = 5f;
[SerializeField]
private float _gravity = 9.81f;
public float rotationSpeed;
private CharacterController controller;
private Animator animator; //for later animation use
// Start is called before the first frame update
private void Awake(){
Player = this;
}
void Start()
{
controller = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
playerMoves();
PlayerData.Instance.Update();
handleAnimation();
}
private void playerMoves()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontalInput, 0, verticalInput);
direction.Normalize();
direction.y -= _gravity;
if (Input.GetKey(KeyCode.UpArrow)|| Input.GetKey(KeyCode.DownArrow)|| Input.GetKey(KeyCode.LeftArrow)|| Input.GetKey(KeyCode.RightArrow))
{
animator.SetBool("isWalking", true);
}
if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow))
{
animator.SetBool("isWalking", false);
}
controller.Move(direction * Time.deltaTime * _moveSpeed); //multiple by Time.deltaTime so it moves once/second. In update it moves once every frame and frame/second can be very high
if (direction!= Vector3.zero)
{
Quaternion toRotation = Quaternion.LookRotation(direction, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
}
}
void handleAnimation()
{
bool isWalking = animator.GetBool("isWalking");
bool isRunning = animator.GetBool("isRunning");
/*if (isMovementPressed)
{
animator.SetBool("isWalking", true);
}*/
}
}
Also somehow he’s not interacting with a door object with OnEnterTrigger. He just passed right through the door without being transported to another scene
The other door worked just fine but idk why this one doesn’t
Here is the script for the door object
public class EntranceToScene : MonoBehaviour
{
public GameObject entrance;
private string NameOfScene { get; set; } //name of the scene you want to go to
public void OnTriggerEnter(Collider other)
{
//print(other.name);
if (other.gameObject.tag.Equals("Player"))
SceneCtrl.Instance.ChangeScene(SceneNameDefine.Scene.GhettoStreet); //how to go to 'nameOfScene' ???????????
}
//constructor for
public EntranceToScene(GameObject entrance, string nameOfScene) //?????
{
this.entrance = entrance;
this.NameOfScene = nameOfScene;
}
}

