Quaternion.Lerp

I am trying to rotate a player when it hits a wall.
I get this error: Operator + cannot be applied to operands of type ‘Quaternion’ and ‘Quaternion’.
Here is my code:

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

public class Wallcheck : MonoBehaviour
{
    public GameObject text;
    public Transform player;
    public float speed = 0.1f;

    void OnCollisionEnter(Collision Collision)
    {
        Debug.Log("Touched");
        text.SetActive(true);
    }

    void OnCollisionStay()
    {
        if(Input.GetButton("Gravity"))
        {
            Debug.Log("RotateGrav");
        } 
        Quaternion startAngle = player.transform.rotation;
        Quaternion targetAngle = startAngle + Quaternion.Euler(-90f, 0f, 0f);
        transform.rotation = Quaternion.Lerp(startAngle, targetAngle, Time.time * speed);
    }

    void OnCollisionExit(Collision Collision)
    {
        Debug.Log("Stopped touching");
        text.SetActive(false);
    }
}

Any help on how to fix it would be appreciated.

Use the * operator instead of +.

1 Like

Like the error says, you can’t add two quaternions together by using +.

However, the quaternions can be “combined” (which results in a geometric cumulation of the rotations they represent) by using * instead. This operator is non-commutative, i.e. L * R does not equal R * L.

Effectively, L will be applied, then R will be applied to whatever L did.