Raycast being weird

To be totally honest, i don’t know much about ray casts (or anything). i actually copy and pasted a few bits and pieces together from the unity Nightmares tutorial project. I have a problem where it sometimes doesn’t follow the cursor for a tiny little bit. the object on the floor layer has a few children and some colliders that stick out of the ground. if i change it’s layer and put a flat plane on the floor layer, will this fix my problem? Here’s the script I used, and sorry if it’s a bit hard to find that part.

using UnityEngine;
using System.Collections;

public class ExperimentalAim : MonoBehaviour {
	public float RotSpeed = 0f;
	private bool paused = false;
	public Rigidbody playerRigidBody;
	public float camRayLength = 100f;
	public int floorMask; 

	// Use this for initialization
	void Start () {

	}

	void Awake () {
		playerRigidBody = GetComponent <Rigidbody> ();
		floorMask = LayerMask.GetMask ("Floor");
	}

	void Turning ()
	{
		// Create a ray from the mouse cursor on screen in the direction of the camera.
		Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
		
		// Create a RaycastHit variable to store information about what was hit by the ray.
		RaycastHit floorHit;
		
		// Perform the raycast and if it hits something on the floor layer...
		if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
		{
			// Create a vector from the player to the point on the floor the raycast from the mouse hit.
			Vector3 playerToMouse = floorHit.point - transform.position;
			
			// Ensure the vector is entirely along the floor plane.
			playerToMouse.y = 0f;
			
			// Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
			Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
			
			// Set the player's rotation to this new rotation.
			playerRigidBody.MoveRotation (newRotation);
		}
	}

	
	// Update is called once per frame
	void Update () {

		Turning();

		/*

		if(Input.GetKeyUp(KeyCode.Escape))
		{
			paused = !paused;
		}

		if (Input.GetKey (KeyCode.LeftArrow) && paused == false) {
		transform.Rotate (Vector3.down * RotSpeed);
		}

		if (Input.GetKey (KeyCode.RightArrow) && paused == false) {
		transform.Rotate (Vector3.up * RotSpeed);
		}

		if (Input.GetKeyDown (KeyCode.DownArrow) && paused == false) {
			transform.Rotate (Vector3.up * 180);
		}

		*/
	}
}

To be totally honest, i don’t know much about ray casts (or anything)

Our documentation and tutorials can help you, take your time to learn something amazing :slight_smile:

http://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting