My Unity is not giving error, or anything. Everything is OK, but the character does not move.
I already looked at the code and no mistake, I move the mouse and nothing happens to the character. The Unity version is 4.6 and the code is this:
public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLenght = 100f;
void Awake(){
floorMask = LayerMask.GetMask ("Floor");
anim = GetComponent<Animator> ();
playerRigidbody = GetComponent<Rigidbody>();
}
void FixUpdate(){
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
Turning ();
Animating (h, v);
}
void Move(float h,float v){
//tertemina o movimento
movement.Set(h,0f,v);
//normaliza o movimento
movement = movement.normalized * speed * Time.deltaTime;
// efetua o movimento
playerRigidbody.MovePosition (transform.position + movement);
}
//girar o jogador
void Turning(){
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask)) {
Vector3 playerToMouse=floorHit.point-transform.position;
playerToMouse.y=0f;
// rotaçao do personagem
Quaternion newRotation= Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
}
void Animating(float h,float v){
bool walking = h != 0f || v!=0f;
anim.SetBool ("IsWalking", walking);
}
}