I've run into a problem.

Posted below is my script for the beginner survival shooter. It would appear that the movement controls work fine, but the mouse controls don’t(being able to turn character). If anyone can point out what is wrong as soon as possible, it would be much appreciated. Thanks.

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 ()
{
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);
}
}

Repost with code tags, please

1 Like

Have you tried debugging your script? If not, please take a look at the link in my signature on how to go about it. If you still have problems please repost with Code Tags as BenZed has suggested. See the other link in my signature if you need help with code tags.

where do I find code tags? im new to this.

Click the How to use Code Tags link in my signature
|
|
V