error CS0103: The name 'velocity' does not exist in the current context

I am using a tutoial

and i keep getting the error “error CS0103: The name ‘velocity’ does not exist in the current context”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
[SerializeField] Transform mainCamera;
[SerializeField] LayerMask layerMask;
float angle = 0;
Rigidbody playerRigidbody;
RaycastHit hit;
private bool jump;
Vector2 inputLookRaw=Vector2.zero;
Vector2 inputMoveRaw=Vector2.zero;
Vector2 inputLook=Vector2.zero;
Vector2 inputMove=Vector2.zero;

void Start()
{
Cursor.lockState = CursorLockMode.Locked;
playerRigidbody= GetComponent();
}

void Update()
{
inputLook = Vector2.Lerp(inputLook, inputLookRaw, Time.deltaTime * 5f);
inputMove = Vector2.Lerp(inputMove, inputMoveRaw, Time.deltaTime * 10f);

//Rotate right left
playerRigidbody.rotation = Quaternion. Euler (Vector3.up * inputLook.x Time.deltaTime * 10f);

//Rotate up down
angle = Mathf.Clamp(inputLook.y * Time.deltaTime * -5f + angle, -60, 60);
mainCamera.localRotation = Quaternion. Euler(new Vector3(angle, 0, 0));

//Movement
velocity = transform.rotation * new Vector3(inputMove.x, 0, inputMove.y) * 3;

//Jump
if (!jump) jump = Keyboard.current.spaceKey.wasPressedThisFrame & Physics.SphereCast(transform.position, .23f, Vector3.down, out hit, .3f, layerMask);

}

private void FixedUpdate()
{
velocity.y = playerRigidbody.velocity.y;
if (jump) { velocity.y = 5f; jump = false; }
playerRigidbody.velocity = velocity;
}

public void OnMove(InputAction.CallbackContext value)
{
inputMoveRaw = value.ReadValue();
}

public void OnLook(InputAction.CallbackContext value)
{
inputLookRaw = value.ReadValue() * .01f / Time.deltaTime;
}

}

9566386--1353322--image_2024-01-06_172329282.png

because its right

velocity = transform.rotation * new Vector3(inputMove.x, 0, inputMove.y) * 3;

you havent defined a velocity, unless you meant the one on your rigidbody - in which case you need to say that

how?

I think i fixed it but i got more errors

9566404--1353328--image_2024-01-06_173941351.png
9566404--1353331--image_2024-01-06_173955657.png

If you’re going to use the code from a tutorial you need to make sure you enter everything exactly as it is shown in the tutorial. All of your errors are solely the result of missing symbols and words. Also if you’re going to paste code use code tags or it’s just an unreadable mess.

I have entered in everything he said perfectly.

No. I watched the code section of the tutorial. You haven’t entered everything perfectly at all.

Everything is perfect I don’t know why I got errors and he didn’t can you please help me?

huh? I would never do anything as stupidenous and monstrous as that.

Oh you watched the beginning the final code is at the end.

I’ve tried but you’re not willing to listen. I’m not here to help you learn how to follow a tutorial.

I will listen now I am sorry for any frustrations I have caused.

Kindly show us where in the video the tutorial creator wrote the exact code that you had:

Rigidbody playerRigidbody.velocity;

You’ll realize that this code was never in the video. This is therefore not perfect. Heed what the people trying to help you are saying. At this point, though, perhaps the best you can do is carefully read every single line and make sure every word and symbol matches.

Really, though. A tutorial should not require other people to help you like this. All you really need is an input device for entering characters into a code editor and the understanding that code needs to be precise, symbols/spelling/capitalization-wise.

I did that but i got more errors

Assets\Animations\Movement.cs(12,39): error CS1026: ) expected
What does it mean Spy master

11.44 is the final product.

Yes, and it’s functional while yours isn’t. You’ve entered it incorrectly.

1 Like

What do you mean sensai?

And the code that you wrote appears nowhere in there. It’s not even valid C# syntax.

Regrettably, if you don’t realize that you did not copy the tutorial script correctly, our hands are tied. Perhaps you should try following along from the beginning. Have a nice day.

Yes Spy-Master