Character won't move... (Input.GetAxis) [JavaScript]

I’m following a tutorial on youtube from 2011, so I’m guessing this has been changed in some way. I have already tried googleing the issue, but nothing helps.
PlayerMovementScript.js:

function Update ()
{
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation,0);
    GetComponent.<Rigidbody>().AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
}

I would guess that the Horizontal and Vertical inputs should be set to something…? I just reset all of the Inputs in Project Settings, but it didn’t help.

Use Debug.Log to see the values returned by Input.GetAxis to see if you’re getting the input you want.
If that works fine then put dummy values instead of them in the AddRelativeForce function to see if something happens.
If still nothing happens then you messed something up with the Rigidbody.

Also you can look into the Rigidbody.MovePosition function.

Nothing happens when I Debug ether. I am however being spammed with this error:

NullReferenceException: Object reference not set to an instance of an object
PlayerMovementScript.Update () (at Assets/Scripts/JavaScript/PlayerMovementScript.js:18)

Here is the entire PlayerMovement.js:

var walkAcceleration : float = 5;
var cameraObject : GameObject;
var maxWalkSpeed : float = 20;
@HideInInspector
var horizontalMovement : Vector2;

function Update ()
{
    horizontalMovement = Vector2(GetComponent.<Rigidbody>().velocity.x, GetComponent.<Rigidbody>().velocity.z);
    if (horizontalMovement.magnitude > maxWalkSpeed)
    {
        horizontalMovement = horizontalMovement.normalized;
        horizontalMovement *= maxWalkSpeed;
    }
    GetComponent.<Rigidbody>().velocity.x = horizontalMovement.x;
    GetComponent.<Rigidbody>().velocity.z = horizontalMovement.y;

    transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation,0);
    GetComponent.<Rigidbody>().AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
    Debug.LogError("Hello?!");
}

I should also mention that I’m new to all this and I don’t really now whet I’m doing… So any help is greatly appreciated.

This usually means that you haven’t assigned a variable in inspector.
Check if you have assigned cameraObject.

Also you should learn to start using the code tags:
[ code ] [ /code ]

I don’t think you can have a period here:

GetComponent.<Rigidbody>()

But I don’t do UnityScript, and I don’t think you can do that with UnityScript.

I think you have to do it like this with UnityScript:

GetComponent(Rigidbody)

Like @The-Little-Guy say.

With C# use:

GetComponent.<Rigidbody>()

With javascript use:

GetComponent(Rigidbody)

I changed all of the “GetComponent.()” to “GetComponent(Rigidbody)” but it still does not work.
I’m still getting the error on line 18 as well. Don’t now whats that all about.

Visual Studio seems to be locked in C# too… How can I change that?

The guy in the video’s code is a bit different though…

var walkAcceleration : float = 5;
var cameraObject : GameObject;
var maxWalkSpeed : float = 20;
@HideInInspector
var horizontalMovement : Vector2;

function Update ()
{
    horizontalMovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
    if (horizontalMovement.magnitude > maxWalkSpeed)
    {
        horizontalMovement = horizontalMovement.normalized;
        horizontalMovement *= maxWalkSpeed;
    }
    rigidbody.velocity.x = horizontalMovement.x;
    rigidbody.velocity.z = horizontalMovement.y;
   
    transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation,0);
    GetComponent(Rigidbody).AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
    Debug.LogError("Hello?!");
}

Do you have to use GetComponent() now? The video is from 2011

@The-Little-Guy

that’s valid unityscript for a typed getcomponent (and yes it looks weird to c# eyes :sunglasses:).

I would suggest you find a better tutorial. You really shouldn’t be using GetComponent in Update to find and access components on the current gameobject that do not change between frames.

Have you looked at the tutorials in the learn section? if you’re looking to work on a “moving through rigidbody and forces” approach have a look at the rollaball tutorial.