3D avatar rotating to 90 not 180

I want my avatar to rotate 180 degrees.

I managed to clamp it to 180, but it’s stuck at 90.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovementScript : MonoBehaviour
{

    public float speed = 5.0f;
    public float rotationSpeed;
    public float jumpForce = 5;
    public bool isOnGround = true;
    public float horizontalInput;
    public float forwardInput;
    private Rigidbody playerRb;

    public float CharacterrotationHorizontal = 0f;

   // Transform Player;

    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        // get player input
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");
        
        // Move the player foward
       // transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput); // - up and down
       // transform.Translate(Vector3.right * Time.deltaTime * speed * horizontalInput); //left and right
        Vector3 movementDirection = new Vector3(horizontalInput, 0); //- This for left and right
        //Vector3 movementDirection = new Vector3(verticalInput, horizontalInput, 0);
        movementDirection.Normalize();

        transform.Translate(movementDirection * Time.deltaTime * speed, Space.World);

        if (movementDirection != Vector3.zero)
        {
            Quaternion toRotation = Quaternion.LookRotation(horizontalInput * Vector3.right, Vector3.up);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
            CharacterrotationHorizontal = Mathf.Clamp(CharacterrotationHorizontal, -180f, 180f);

            //Player(transform.rotation, Vector3.up * CharacterrotationHorizontal);
            
            print(CharacterrotationHorizontal);
        }

        //Let the player jump
        if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
        {
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            isOnGround = false;
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            isOnGround = true;
        }
    }
}

Are you just writing Yet Another Character Controller?? Do you really want to hassle with writing your own CC? It’s pretty difficult obtuse stuff, certainly NOT a beginner topic at all.

If so, tuck in and prepare to do some deep debugging. Meanwhile, if you just want one to use in your game and move forward, here’s two:

Here is a super-basic starter prototype FPS based on Character Controller (BasicFPCC):

That one has run, walk, jump, slide, crouch.

And here is a free Kinematic Character Controller that also comes with a huge playground:

Thank you.

But all I wanted what to find out why the character isn’t rotating 180 degrees.

The link you sent me doesn’t have a rotating character.

Both of those can be rotated. If that’s not what you mean by a “rotating character,” then it is time for you to explain further.

Your code appears to handle rotation around line 45.

Are you just trying to make the character rotate between facing right or facing left based upon if it is going left or going right?

Is the root ‘Player’ game object rotated (potentially by 90 degrees)?

It would mean rotating the player to world right/left would give the impression its rotating 180 degrees, but it’s only 180 degrees locally. Remember the inspector for the transform shows local values, and not world ones.

CharacterrotationHorizontal = Mathf.Clamp(CharacterrotationHorizontal, -180f, 180f);

I tried to make it rotate 180, and I tried changing it in the editor, but nothing worked.

It’s the camera clamp code, but for the player model.

I’m making a 2D style game

That’s why you can only move left and right.

I wanted the character to rotate to the left or right.

And like show the rotation.

If you want to check out my 2.5D/25D treatment, see my Proximity Buttons project and look for the Demo25DMovement scene.

It is done with 3D objects but it could just as easily be sprites.

Specifically, the PivotingVisuals Transform on line 47 here:

Pay attention to desiredVisualsFacing and how it gets set based on left/right, and then how VisualsFacing is moved towards it, around line 108.

proximity_buttons is presently hosted at these locations:

Thank you,

But I think I might change the character into a first-person.

it might be easier.