2
My Unity is not giving error, or anything. Everything is OK, but the character does not move.
I’ve looked at the code and no mistakes, I move the mouse and nothing happens to the character. 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);
}
}
http://answall.com/questions/49919/como-girar-o-personagem-conforme-o-movimento-do-mouse
– Renan Gomes
It is not duplicated, the problem is different from the one that sent the link. Just see the code, the "Floor" is correct in this.
– Nils
@Nils Well, I didn’t score as a duplicate, I just posted a link of a question of similar title.
– Renan Gomes
@I just wanted to warn the moderator, I didn’t know about the signal button. A lot of people saw this link and how the question name was the same they signaled as duplicate.
– Nils