I want to create a first person perspective character controller that allows for walking on walls and ceiling by transitioning with a slope (kinda like the anti-virus levels in Rachet & Clank: Rift Apart), after searching and working out code with quaternions I got code for rotation like below, but the problem is that when using slerp for smoother transitioning it stays around 15 degrees off from the target angle until I stop moving.

I use FPP for character controller and mouse for controlling camera and movement rotation but it's done in localSpace on object that is child of the object that is doing rotation with the code below:

Vector3 forward = transform.forward * 0;
        Vector3 positionStart = transform.position;
        Ray ray = new Ray(positionStart, -transform.up + forward);
        bool status = Physics.Raycast(ray, out RaycastHit hitInfo, 1f);
        if (status)
            Quaternion slopeRotation = Quaternion.LookRotation(Vector3.Cross(transform.forward, hitInfo.normal), hitInfo.normal);
            transform.rotation = Quaternion.Slerp(transform.rotation, slopeRotation, 10 * Time.deltaTime);

Here's a video of what's happening.

Notice that when transitioning from floor to wall it keeps a bit of an angle unless I stop.

  • 1
    \$\begingroup\$ I'll just go ahead and say that the first two lines are a bit of remainder code from testing, when I was looking for solutions \$\endgroup\$
    – Gludek
    Jul 26 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.