x


CharacterController NullReferenceException dispite attached to object

Hi,

I am writing a movement script using CharacterController. I have a characterController component attached to my object, but, it keeps returning a NullReferenceException. I have tried creating a new object as well as importing one of the example objects, but nothing seems to work. Below is all the code in the script that mentions the CharacterController.

 private var character : CharacterController;

 character = GetComponent(CharacterController);

 if(this.transform.position != standardPos)
     {
         var target : Vector3 = standardPos;
         target.y = transform.position.y; // keep waypoint at character's height
         var moveDirection : Vector3 =  target - transform.position;
         if(moveDirection.magnitude < 1)
         {
             transform.position = target; // force character to waypoint position
         }
         else
         {
               Accelerate();
 
            transform.LookAt(target);
 
             character.Move((moveDirection.normalized*speed)*Time.deltaTime);
        }
     }
more ▼

asked May 31, 2013 at 12:39 AM

Mithosbluefish gravatar image

Mithosbluefish
20 11 14 16

Wow, herp derp :P thanks :P

May 31, 2013 at 06:11 PM Mithosbluefish

I made that an answer so you can accept it and this question can be forever closed :)

Jun 01, 2013 at 08:24 AM Benproductions1

Is this all located in Update?

May 31, 2013 at 05:05 AM Benproductions1
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Place that code in the Update function and it will work :)

more ▼

answered Jun 01, 2013 at 08:24 AM

Benproductions1 gravatar image

Benproductions1
13.1k 30 34 58

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2617
x1544
x1188
x864
x787

asked: May 31, 2013 at 12:39 AM

Seen: 533 times

Last Updated: Jun 01, 2013 at 08:24 AM