Why can't I move my player?
I'm currently following the survival shooter tutorial Player Character and it says the it has no errors but when i press play I can't move PLEASE HELP I HAVE TO FINISH THE TUTORIAL IN A MONTH My script is
using UnityEngine;
public class PlayerMouvement : MonoBehaviour { public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;
void Awake()
{
floorMask = LayerMask.GetMask("Floor");
anim = GetComponent<Animator>();
playerRigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
Move(h, v);
Turning();
Animating(h, v);
}
void Move(float h, float v)
{
movement.Set(h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidbody.MovePosition(transform.position + movement);
}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
}
void Animating(float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool("IsWalking", walking);
}
}
Comment
Answer by Martians · Apr 21, 2017 at 06:21 PM
I would use the character controller that unity provides. Is the game 2d or 3d?
Your answer
Follow this Question
Related Questions
Character movement 0 Answers
Make character face movement direction 0 Answers
I can't move my player in a fps? 1 Answer
Player is not moving if i apply the Playerbounds 0 Answers
Photon Player Mover Failure 1 Answer