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

