Keyboard rotating - left is stopping object

Hi,

when I rotate right during moving forward, it will do both - moving and rotate (my track will be a circle), but when I rotate left, it will do only rotation, my movement speed is 0 (my track is point of rotation).

For moving I use parts of Character Controller from Standard Assets (Character Controller, Character Motor, FPSInput Controller)

and I have this easy script for rotating player with keyboard:

void Update()
    {
        float speed = 100f;

        if (Input.GetButton("left"))
        {
            gameObject.transform.Rotate(-transform.TransformDirection(Vector3.up), Time.deltaTime * speed);
        }
        
        if (Input.GetButton("right"))
        {
            gameObject.transform.Rotate(transform.TransformDirection(Vector3.up), Time.deltaTime * speed);
        }
}

Buttons are correctly preset in Edit->Project Settings → Input
left positive button is q and right positive button is e

I've seen this with characters that have child objects with colliders. If you have child objects of the character, try disabling them, or at least disabling their colliders.

It didnt help, man :(

1 Answer

1

Instead of doing “-transform” try doing -speed at the end of the function and remove the - from your transform.

Still the same :/ I tried to do gameObject.transform.rotation = new Quaternion(0, gameObject.transform.rotation.y - speed, 0, gameObject.transform.rotation.w); but, it has interesting issue. When I'm facing one direction, it has rotating speed about 0.001f a and when i turn around, it will have normal 1f as I had