How do I define Move?

Okay, so I’m watching a tutorial with nearly 80k views that told me what to code, but when I run this it says there is no definition for “Move.” I know it wasn’t given one, but the tutorial’s code has no errors for some reason? I triple checked for errors in spelling but there are none and it still doesn’t work. How do I give Move a proper defenition?

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

public class CharacterController : MonoBehaviour {

    public float moveSpeed;

    public float jumpForce;

    public CharacterController controller;

    private Vector3 moveDirection;
   
    // Start is called before the first frame update
    void Start() {
       
    controller = GetComponent<CharacterController>();

    }

    // Update is called once per frame
    void Update() {
       
    moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0f, Input.GetAxis("Vertical") * moveSpeed);

    if (Input.GetButtonDown("Jump")) {

      moveDirection.y = jumpForce;

    }

    controller.Move(moveDirection * Time.deltaTime);

    }
}

CharacterController already has a definition for Move: Unity - Scripting API: CharacterController.Move

Would you mind pasting the entire error message, including the line number part?

Here’s the error message:

Assets\CharacterController.cs(33,16): error CS1061: ‘CharacterController’ does not contain a definition for ‘Move’ and no accessible extension method ‘Move’ accepting a first argument of type ‘CharacterController’ could be found (are you missing a using directive or an assembly reference?)

Oh so… did you make your own script called CharacterController? I was assuming you were using the builtin version from Unity: Unity - Scripting API: CharacterController

Did they make their own custom CharacterController class in the tutorial?

Edit: Duh - just looked at your script. Try renaming your script to something else, because Unity has a CharacterController already and I think you’re probably running into trouble because of that.

I renamed the script but am still getting the error. The tutorial does have a CharacterController class, I copied their code word for word.

Edit: I am also using the built in CharacterController for my Player. I think the problem might be that I am not referring back to it?

You can make sure you’re using Unity’s built in character controller by changing the variable declaration to this:

public UnityEngine.CharacterController controller;

and changing the line in Start to this:

controller = GetComponent<UnityEngine.CharacterController>();

But really you’ll have a much easier time if the names are different. Would you mind sharing which tutorial you’re following?

2 Likes

Here’s the tutorial:

https://video.search.yahoo.com/video/play;_ylt=AwrC5plBZTVfgkYAot80nIlQ;_ylu=X3oDMTBzZWQ1aGR0BHNlYwNzcgRzbGsDdmlkBHZ0aWQDBGdwb3MDMTI-?p=make+a+3d+platformer&vid=fe6654a2ac6f7fa4487ba3d5cbf2f560&turl=https://tse2.mm.bing.net/th?id=OVP.lLR8SrklgaJBq3vC4JKDIgHgFo&pid=Api&h=360&w=480&c=7&rs=1&rurl=https://www.youtube.com/watch?v=p5OWasgD1no&tit=Make+A+3D+Platformer+in+Unity+#3:+Better+Movement&c=11&h=360&w=480&l=1206&sigr=4as7pprMpfyy&sigt=ZIOAU2xY6qvq&sigi=414_s6yBx0u9&age=1499446825&fr2=p:s,v:v&fr=yhs-avast-securebrowser&hsimp=yhs-securebrowser&hspart=avast&type=1102&param1=c0ecc42b25b645a59a09a4509e28be44&param2=20180519&param3=Avast+Secure+Browser|84.0.5270.105&param4=17|US|1.23.0.675|1.23.0.675&tt=b

I added the mew lines but now I get this error:
Assets\Player Movement.cs(36,1): error CS1022: Type or namespace definition, or end-of-file expected

What do I need to add? 36 is my last line
Thanks for all the help btw :slight_smile: