Slow rotate for up axis not working (image attached).

I want my capsule’s up axis to point towards an object. Here’s my code:

    void Update () {
        Vector3 direction = cube.transform.position - transform.position;
        Debug.DrawRay(transform.position, direction * 1000, Color.green);
        Debug.DrawRay(transform.position, transform.up * 1000, Color.blue);


        Quaternion toRotation = Quaternion.FromToRotation(transform.up, direction);
        transform.rotation = Quaternion.Slerp(transform.rotation, toRotation, 5f * Time.deltaTime);
    }

‘cube’ is an object in the 3d world (see attached image). The green ray hows the direction the character’s up axis should become aligned with while the blue ray shows the character’s up axis direction. I cannot figure out why this code is not making the character’s up axis point towards the cube. My capsule starts off lying down so its x rotation value is 90 starting out. Any ideas?

2665358--188067--Untitled.png

I didn’t test this in Unity myself, but you should propably normalize the vector first

Vector3 direction = (cube.transform.position - transform.position).Normalized;
1 Like

@Zaflis Thanks - that fixed it.