I mean…the error is pretty clear. But for a solution, it can be hard to help without showing your code.
If you double click the error, it will take you to it in the script as well. But, what it says, t_direction doesn’t exist in the current context. So when you find t_direction in the script, make sure you spelled it right and caps matter. Otherwise, make sure it’s declared somewhere that it can access.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public float jumpHeight = 3f;
public float sprintModifier;
private Rigidbody rig;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
// Start is called before the first frame update
void Start()
{
rig = GetComponent();
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance,groundMask);
if(isGrounded && velocity.y <0)
velocity.y = -2f;
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis(“Horizontal”);
float z = Input.GetAxis(“Vertical”);
bool sprint = Input.GetKey(KeyCode.LeftShift);
bool isSprinting = sprint;
Vector3 move = transform.right * x + transform.forward * z;
float t_adjustedSpeed = speed;
if (isSprinting) t_adjustedSpeed *= sprintModifier;
rig.velocity = transform.TransformDirection(t_direction) * t_adjustedSpeed *Time.deltaTime;
controller.Move(move * speed * Time.deltaTime);
if(Input.GetButtonDown(“Jump”) && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
You must have missed something in your tutorial. you’re not declaring the t_direction variable anywheere in your script. You cannot use undeclared variables in C#.
Also please use Code Tags when posting code to the forums in the future.
