private void handleVerticalSlope( ref Vector3 deltaMovement )
{
// slope check from the center of our collider
var centerOfCollider = ( _raycastOrigins.bottomLeft.x + _raycastOrigins.bottomRight.x ) * 0.5f;
var rayDirection = -Vector2.up;
// the ray distance is based on our slopeLimit
var slopeCheckRayDistance = _slopeLimitTangent * ( _raycastOrigins.bottomRight.x - centerOfCollider );
var slopeRay = new Vector2( centerOfCollider, _raycastOrigins.bottomLeft.y );
DrawRay( slopeRay, rayDirection * slopeCheckRayDistance, Color.yellow );
_raycastHit = Physics2D.Raycast( slopeRay, rayDirection, slopeCheckRayDistance, platformMask );
if( _raycastHit )
{
// bail out if we have no slope
var angle = Vector2.Angle( _raycastHit.normal, Vector2.up );
if( angle == 0 )
return;
// we are moving down the slope if our normal and movement direction are in the same x direction
var isMovingDownSlope = Mathf.Sign( _raycastHit.normal.x ) == Mathf.Sign( deltaMovement.x );
if( isMovingDownSlope )
{
// going down we want to speed up in most cases so the slopeSpeedMultiplier curve should be > 1 for negative angles
var slopeModifier = slopeSpeedMultiplier.Evaluate( -angle );
deltaMovement.y = _raycastHit.point.y - slopeRay.y - skinWidth;
deltaMovement.x *= slopeModifier;
collisionState.movingDownSlope = true;
collisionState.slopeAngle = angle;
}
}
}