31 Replies
you did not assign any object to a public field in inspector
aka you have a public variable
that's visible in inspector
but it's empty
how to fix
the error message literally says that you need to assign some object to it
But how..
like, by drag and drop
im not blind i know how to read
to where
show me a screenshot of your ThirdPersonMovement script in inspector
k one min
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour
{
public CharacterController controller;
public Transform cam;
public float speed = 6f;
public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
public Transform cam;
this field is visible in inspector
by inspector I mean in Unity
you have to grab object representing your camera and drag it to this field in Unity
if you're following a tutorial it should be shown therecant see public transform cam
@WinForms Sam
show me a screenshot from Unity
where your script shows
this?
yes]
alr what now
here
you have empty field for cam
and for character controller
what do I do
oh nvm
cant change controller tho
I can only change cam
do you have a character controller?
cam is falling down
when I run it
no
I just added
check if you did everything as he did in tutorial
the cam is moving
when I do wasd
and its lagging
when I do it
I think I did.....
you obviously did not
since it's not working
can u add me so I can create a groupchat with my frien
and he can screen share
sorry, but I don't have that much time
ugh
I straight
copied the code
that the tutorial man mentioned
check if you assigned right camera
and see if he perhaps did something more
do you want me to send any kind of ss
cause I can barely understand
watch what he did step by step
I can't really help more, sitting here, miles away
Do not blindly copy paste
That's how you get stuck in tutorial-hell
Understand what the code does.
Also, do not learn C# in Unity. Please.
I suggest learning by doing, $helloworld is a good start.