Why this script not working?

I have this script:

  public float threshold;

  private bool isGrounded;

  void OnTriggerEnter(Collision other) 
{
   foreach(ContactPoint temp in other.contacts) {
    if(Vector3.Cross(temp.normal, Vector3.up) < threshold) {
        isGrounded = true;
    }
}

}

The error says that operatos of < cant be applied to Vector3 and float, how can I fix this?

What it does is check the collider bounds to see if it is grounded.

The left side of your if statement is a Vector3, since that is what Vector3.Cross() returns.

The error occurs because you can’t compare set of 3 floats with 1 float.

Vector that is returned there is also normalized which means its magnitude equals 1 so no point in using someNormalizedVector.magnitude since it is a fixed value.

My first thoughts for ground checking would be raycasting or using collider.isGrounded which natively does not give usable results but I made a workaround for that, you can find the code and unitypackage working scene with separated raycast scene, char controller and both combined with explanations here. Good luck!

Radivarig

OnTriggerEnter has to be Collider not Collision