Movement script not working on imported model

My script so far is really basic, I wanted to get my character moving before moving onto the more interesting things.

My Code:

    var speed : float = 6.0;
    var jumpSpeed : float = 8.0;
    var gravity : float = 20.0;
    private var moveDirection : Vector3 = Vector3.zero;
    
    function Update () 
    {
    	var controller : CharacterController = GetComponent(CharacterController);
    	if(controller.isGrounded)
    	{
    		moveDirection = Vector3(Input.GetAxis( "Horizontal" ), 0, Input.GetAxis( "Vertical" ));
    		moveDirection = transform.TransformDirection(moveDirection);
    		moveDirection *= speed;
    		
    		if(Input.GetButton ( "Jump" ))
    		{
    			moveDirection.y = jumpSpeed;
    		}
    	 }
    	 
    	 moveDirection.y -= gravity * Time.deltaTime;
    	 
    	 controller.Move(moveDirection * Time.deltaTime);
    }

The problem I’m having is that, while this code works on spheres and anything else I attach it too (as long as it has a CharacterController) But it doesn’t seem to work on my imported model?

The model I’ve imported I created in 3DS Max Design and imported it as an .FBX file. It’s in two separate parts, a ‘body’ and a ‘head’ and there both parented under ‘Character Full’.

I’ve been putting the script on Character Full and it does nothing, so tried putting it on just the ‘body’ and it started rolling around and going who knows where, without the head. Tried putting the script on all three parts as well, also didn’t work out.

Any help would be appreciated, sorry if this question has been asked before I wasn’t sure what to search for!

You need to make sure you have the correct attributes applied to your important object, such as the CharacterController. Try putting the ‘body’, and ‘head’ into an ‘empty’, then placing this script onto that empty as well as the character controller.

Also, try adding a Rigidbody

This script needs to have a CharacterController component attached to the same object, you could easily add one on your imported model, the same place where you put this script.

Also i would advise moving this line:

var controller : CharacterController = GetComponent(CharacterController);

…to your Awake() Method, as you only need to get the CharacterController once (bad for performance to get it and assign it every frame & unnecessary in this case), but to that you have to declare (var controller : CharacterController) outside .

Thanks for the fast response guys!

I’ve tried putting ‘body’ and ‘head’ into a new empty with the same result, no movement at all. Adding a rigidbody just makes my character fall through the floor, or if i turn gravity off it just hovers in place.

I’ll try your suggestions again, gotta be a simple problem somewhere.