Beispiel #1
0
    private GameObject GetClosestTarget()
    {
        if (targets.Count == 1)
        {
            return(targets[0]);
        }

        return(TargetingTools.FindNearestTarget(targets, transform));
    }
Beispiel #2
0
    public Vector2 CalcDirectionAndForce(GameObject target, GameObject source)
    {
        Vector2 result = Vector2.zero;

        switch (directionType)
        {
        case DirectionType.AwayInLine:
            result = (target.transform.position - source.transform.position).normalized;

            Debug.Log((result * amount) + " is being applied");
            break;

        case DirectionType.Up:
            result = Vector2.up;
            break;

        case DirectionType.Down:
            result = Vector2.down;
            break;

        case DirectionType.Forward:
            result = source.Entity().Movement.Facing == EntityMovement.FacingDirection.Left ? Vector2.left : Vector2.right;
            break;

        case DirectionType.Backward:
            result = source.Entity().Movement.Facing == EntityMovement.FacingDirection.Left ? Vector2.right : Vector2.left;
            break;

        case DirectionType.CustomAngle:

            float offset = Random.Range(-error, error);

            //Debug.Log(angle + " ANGLE");
            //Debug.Log((angle + offset) + " OFFSET ANGLE");

            Vector2 conversion = TargetingTools.DegreeToVector2(angle + offset);

            if (source != null)
            {
                conversion = source.Entity().Movement.Facing == EntityMovement.FacingDirection.Left ? new Vector2(-conversion.x, conversion.y) : conversion;
            }

            result = conversion;

            break;
        }

        result *= amount;

        return(result);
    }