using UnityEngine;

public class Movement : MonoBehaviour
{
    public float turnSpeed = 1f;
    public float speed = 2f;
    Animator animator;

    private void Start()
    {
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Dialog.manager.play) return;

        float front = (Input.GetKey(KeyCode.W) ? 1 : 0) + (Input.GetKey(KeyCode.S) ? -1 : 0);
        float side = (Input.GetKey(KeyCode.D) ? 1 : 0) + (Input.GetKey(KeyCode.A) ? -1 : 0);
        Vector3 targetDirection = transform.forward * front + transform.right * side;
        transform.Translate(targetDirection.normalized * speed * Time.deltaTime, Space.World);

        animator.SetFloat("speed", targetDirection == Vector3.zero ? 0 : speed);
        animator.SetBool("ladder", Input.GetKey(KeyCode.Space));
        transform.Rotate(0, Input.GetAxis("Mouse X") * turnSpeed, 0);
    }

   

}
