Problem with character controler

Hi there.

I am having problems with the character controller.
It seems that when I make the controller move in any direction it needs to accelerate for about 2 tenths of a second to reach max speed.
To me it feels almost like lag. I need my character to instantly move at the designated speed without the need to accelerate. Is this possible with the default character controller?
If I make my own controller I seem to run into other problems with the collider when running into walls and I also have trouble making the character jumping feel right.

I am currently using the following script:

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) {
        // We are grounded, so recalculate
        // move direction directly from axes
        moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection *= speed;
        
        if (Input.GetButton ("Jump")) {
            moveDirection.y = jumpSpeed;
        }
		
    }

    // Apply gravity
    moveDirection.y -= gravity * Time.deltaTime;
    
    // Move the controller
	controller.Move(moveDirection * Time.deltaTime);
}

I think…

You need to apply gravity only if the controller is not grounded.

So:

if(controller.isGrounded){
//do your business
}
else{
//apply gravity
}

-JFFM

I recommend changing your “function Update()” to “function FixedUpdate()” instead. :slight_smile:
That’s where the problem is.

Hey!!!

Your Code is absolutely correct but instead of using Update() you should use FixedUpdate()…that might solve your prob.

Go to your Input settings and set Gravity and Sensitivity in both Horizontal and Vertical inputs to something like 10,000.

Vicenti has it right. The problem isn’t in your code, however have a look at the following line;

moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

What’s happening here is that you are multiplying the values for your move directions by the values for “Horizontal” and “Vertical”. With other inputs they are usually digital on/off affairs, so you’d press the button and these values would immediately jump from 0 to 1 (which would be fine for you). However these ones are by default smoothed out so that it takes a configurable amount of time for them to change values between -1, 0 and 1, making it a bit more like an analog stick type of input. Sensitivity tells it how quickly it should change from 0 to either -1 or 1 when you press a key, and gravity tells it how quickly it should return to 0 when you let go of keys. Putting them both to 10000 through the Input Settings is fine, but if you’re a bit anal like me you can just set them both to Infinity so they jump instantly.

Thank you. That actually makes sense! Gonna try it first chance i got :slight_smile: