Rotating on y axis after transform.up has been altered?

So I have a car and I send a raycast downwards to find the rotation of the ground beneath it, and I rotate the car so that it matches its rotation with the ground.

I also have another function which moves the car based on my horizontal input. How do I make it so that, while the RotationOnHeight function alters the transform.up, I can also rotate the car on Y axis?

 void RotationOnHeight()

 {

        RaycastHit hit;

        if (Physics.Raycast(van.position, -van.up, out hit, vanHeight, drivable))
        {print ("van close enough");
        Debug.DrawLine(van.position, hit.point, Color.red);
        van.up = Vector3.Lerp(van.up, hit.normal, Time.deltaTime * rotateDampen);
        //van.transform.rotation = Quaternion.LookRotation(rb.velocity, van.up);
        van.Rotate(van.up.x, van.eulerAngles.y, van.up.z);
        }
        else
        {
            print("No rays");
        }
    }

void Steer()
    {

        float absoluteVeloX = Mathf.Abs(rb.velocity.x);
        float absoluteVeloZ = Mathf.Abs(rb.velocity.z);

        float absoluteVelocity = (absoluteVeloX + absoluteVeloZ) / 2f;
        //print("Absolute velocity: " + absoluteVelocity);
        horizontal = Input.GetAxis("Horizontal");

        switch(horizontal)
        {
            case -1:
            float currentRotation = horizontal;
            print("should go left");
            

            
            rb.AddForce(-van.right * rotateSpeed, ForceMode.Acceleration);
           
            break;
            case 1:
            print("should go right");
            
            rb.AddForce(van.right * rotateSpeed, ForceMode.Acceleration);


            break;
        }
    }

It almost works with Quaternion.LookRotation, but this time the object turns completely 180 degrees if I’m moving it backwards.

To create a rotation around an axis, you use Quaternion.AngleAxis. Then you can combine the resultant rotation with an existing rotation by multiplying them together.

However you are combining non-physics movement with physics movement here. You should consolidate that to be either entirely physics, or entirely non-physics. Likely keep it physics based, and route all movement through the rigidbody, such as using .MovePosition/Rotation rather than manually altering the transform directly.

Ah I see. Makes sense. See what I’m doing is, I have this sphere rigidbody and I have the car model that follows it around. It actually works like a charm in terms of fluidity and game feel.

So just to make sure I understand you correctly, if I mean to keep my RotationOnHeight function relatively intact, I should use quaternion.angleaxis ? Because I can’t use the rigidbody’s rotation, since it is a sphere it is always rotating all over. It is the car model’s rotation that I want to alter.