using System.Collections; using System.Collections.Generic; using UnityEngine;
public class movimentar : MonoBehaviour{ public float Velocidade = 10; Vector3 direcao ; public LayerMask chao;
// Update is called once per frame
void Update(){
float eixoX = Input.GetAxis("Horizontal");
float eixoZ = Input.GetAxis("Vertical");
direcao = new Vector3(eixoX,0,eixoZ);
if(direcao != Vector3.zero){
GetComponent<Animator>().SetBool("Mover",true);
}else{
GetComponent<Animator>().SetBool("Mover",false);
}
}
void FixedUpdate(){
GetComponent<Rigidbody>().MovePosition
(GetComponent<Rigidbody>().position +(direcao * Velocidade * Time.deltaTime));
Ray raio = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(raio.origin,raio.direction * 100,Color.red);
RaycastHit impacto;
if(Physics.Raycast(raio, out impacto, 100)){
Vector3 posicaoJogador = impacto.point - transform.position;
posicaoJogador.y = transform.position.y;
Quaternion novaRotacao = Quaternion.LookRotation(posicaoJogador);
GetComponent<Rigidbody>().MoveRotation(novaRotacao);
}
}
}