Hey guys im new to unity and kind of new to coding. Im on the second lesson in the survival shooter tutorial and i have one major issue. My character does not move. none of my computer controls work on him. i thought it was just my computer being slow but the idle animation is playing so i know its running. I even copy and pasted the code after coming through it for hours, but it still doesnt want to move.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;
void Awake()
{
floorMask = LayerMask.GetMask(“Floor”);
anim = GetComponent();
playerRigidbody = GetComponent();
}
void FixedUpdate()
{
//Raw input gives us -1, 0, or 1 only. Nothing inbetween.
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);
//Needs to be normalised because the vector of x=1 and y=1 is 1.4, so movement will be irregular
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);
}
}[/code]