Help me debug the issue
I have a fairly simple bit of code which Im trying to use to find the slope angle of the slope below me. The method is referenced in the Update method. For some reason, it wont return 0 degress on flat ground and literally decides to check the slope whenever it feels like it instead of all the time or at least following a pattern I can see. Id appreciate it if someone got point out whats wrong because Ive spent so long trying to find the issue.
void CheckSlope () {
float directionX = collisions.faceDir;
Vector2 rayOrigin = (directionX == -1) ? bottomLeft : bottomRight;
RaycastHit2D hit = Physics2D.Raycast (rayOrigin, -transform.up, Mathf.Infinity, collisionMask);
Debug.DrawRay(rayOrigin, -transform.up, Color.green);
if (hit) {
float slopeAngle = Vector2.Angle (hit.normal, transform.up);
print (slopeAngle);
}
}
Comment