Error in PlayerMovement.cs

I was trying to learn watching the Survival Shooter Tutorial, and got this error on PlayerMovement.cs:

Assets/Scripts/Player/PlayerMovement.cs(45,36): error CS0103: The name `floorHit' does not exist in the current context

I don’t know why it happened, I’m sure that I’ve done everything like they did.

My script is writen like this:

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 <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 flootHit;

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

Unity tells me the wrong line is this:
if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))

How can I fix this?
Can someone help me here?

Please use code tags Using code tags properly

Your error indicates that floorHit doesn’t exist. If you look through you code you will see that you haven’t declared any floorHit variable. Instead you wrote flootHit

1 Like

Thanks!
Is there any place to learn about creating a variable? This is my first try to script, and at the moment I can just follow instructions.
Thanks again.


EDIT:

@Rotary-Heart
I found my own mistake. In line 43 I wrote RaycastHit flootHit, instead of RaycastHit floorHit
Thanks again!

Help me this is error

using System.Collections;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovment : MonoBehaviour
{

public CharacterController2D controller;

public float runSpeed = 40f;

float horizontaleMove = 0f;
bool jump = false;

void Update() {
horizontaleMove = Input.GetAxisRaw(“Horizontal”) * runSpeed;

if (input.GetButtonDown(“jump”))
{
jump = true;
}
]

void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, false);
jump = false;
{

}

}

  1. use code tags (see above!)
  2. what is the error? (exact text please)
  3. what line is it on?
  4. what do you expect it to do?
  5. what does it do that displeases you?

And generally, don’t respond to threads from three years ago. Just make a new thread. Nobody is going to bill you for it and it simplifies what is going on.

i have this problem too,pls help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
private readonly Debug.Log input.AxisRawHorizontal;

// Start is called before the first frame update
void Start()
{

}

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

private Debug.Log GetInput.AxisRawHorizontal() => input.AxisRawHorizontal;
}