示例#1
0
 public virtual void Awake()
 {
     _raycastLauncher = GetComponent <RaycastLauncher>();
     _sprite          = GetComponentInChildren <SpriteRenderer>();
     _animator        = GetComponentInChildren <Animator>();
     Physics          = GetComponent <Physics>();
 }
示例#2
0
    private float Colliding(RaycastLauncher launcher, Vector2 direction, float rayDistance)
    {
        var hits = launcher.GetHitData(direction, rayDistance, _margin).Where(x => x.distance > 0).ToList();

        if (hits.Count == 0)
        {
            return(0);
        }
        return(hits.Min(x => x.distance));
    }
示例#3
0
    private (float, float) CollidingWithSlope(RaycastLauncher launcher, Vector2 direction, float rayDistance)
    {
        var hits = launcher.GetHitData(direction, rayDistance, _margin).Where(x => x.distance > 0).ToList();

        if (hits.Count == 0)
        {
            return(0, 0);
        }

        var minDist = hits.Min(x => x.distance);
        var minHit  = hits.First(x => x.distance == minDist);

        var angle = Vector2.Angle(minHit.normal, Vector2.up);

        if (Mathf.Abs(angle) < _angleLeeway || (angle == 90 && OnlyOneHit(hits)))
        {
            return(0, angle);
        }
        else
        {
            return(minDist, angle);
        }
    }