Need character controller to make sharp 90 degree turns and not slide when turning

Hello,

I’m using the first person controller for my characters movement. On a left arrow keypress, I’d like the character to instantly rotate 90 degrees and keep moving forward. Currently, when I hit the arrow key, the character makes the sharp 90 degree turn, but the forward momentum the character previously had takes a second to wear off so the character ends up sliding in the direction he was previously moving a short bit.

The closest example I can think of to visually explain what I’m trying to do is how the character turns sharp in Temple Run. How my game is currently working, if I had the character on a ledge make a sharp left turn, he’d likely keep the original momentum and slide off the edge right after he turns.

Since my character is running on the x/z axis, I’m wondering if there would just be some way to maybe swap the directional velocity/momentum? The speed the character had on the x axis would instantly be switched to the z when it turns and the other would be set to zero. I’m obviously open to any solution that accomplishes what I’m looking for.

I dug into the CharacterMotor class in the first person controller, but have yet to find what part I can tweak to accomplish this.

I’d greatly appreciate any help.

Thank you.

First, do you need the CharacterMotor script? What functionality specifically are you getting out of it that you cannot get out of simpler scripts? Second can you post the code you are using to drive the CharacterMotor scripts?

2 Answers

2

I’m having a similar trouble, except I’m not using a First Person view. if you keep the left key pressed does he rotate indefinitely or does it clamp ?
How do you have your friction settings ? if you lower it to 0 he will quit sliding.

you mean like this?

http://dl.dropbox.com/u/11203897/ToasterSandwich.html

here’s the script:

#pragma strict

var direction : Vector3;
var controller : CharacterController;
var speed = 5;

function Start () {
direction = transform.forward;
controller = GetComponent(CharacterController);
}

function Update () {

controller.Move(direction * speed * Time.deltaTime);

    if(Input.GetKeyDown("left")){
    transform.Rotate(0,90,0);
    direction = transform.forward;
    }
    if(Input.GetKeyDown("right")){
    transform.Rotate(0,-90,0);
    direction = transform.forward;
    }

}