Esempio n. 1
0
 public override bool PerformAction()
 {
     if (update)
     {
         Vector2 directionOfMove = aim.GetLocation() - body.position;
         body.rotation = Vector2.Angle(Vector2.up, directionOfMove) * (directionOfMove.x > 0 ? -1 : 1);
     }
     return(true);
 }
Esempio n. 2
0
 public override bool PerformAction()
 {
     if (update)
     {
         if (monopoliseRotation)
         {
             movement.ApplyInfluenceRotation(-movement.GetInfluenceRotation());
         }
         movement.ApplyInfluencePointRotation(aim.GetLocation(), rotationSpeed);
     }
     return(true);
 }
Esempio n. 3
0
    public override bool CanEnter()
    {
        float distanceSq = ((Vector2)transform.position - aim.GetLocation()).sqrMagnitude;
        bool  b = distanceSq <distanceMax *distanceMax && distanceSq> distanceMin * distanceMin;

        return(inside ? b : !b);
    }
Esempio n. 4
0
    public override bool CanEnter()
    {
        Vector2 direction = (Vector2)myMind.transform.position - aim.GetLocation();
        Vector2 prepDir   = new Vector2(-direction.y, direction.x).normalized;
        int     n         = Physics2D.RaycastNonAlloc((Vector2)myMind.transform.position + prepDir * raysOffset, direction.normalized, hits, direction.magnitude);

        for (int i = 0; i < n; ++i)
        {
            var it   = hits[i];
            var unit = it.collider.GetComponent <AiPerceiveUnit>();
            if (unit && unit.fraction &&
                (unit.fraction.fractionName == fractionName ||
                 unit.fraction.GetAttitude(myMind.myFraction.fractionName) == attitude)
                )
            {
                return(false);
            }
        }
        n = Physics2D.RaycastNonAlloc((Vector2)myMind.transform.position - prepDir * raysOffset, direction.normalized, hits, direction.magnitude);
        for (int i = 0; i < n; ++i)
        {
            var it   = hits[i];
            var unit = it.collider.GetComponent <AiPerceiveUnit>();
            if (unit && unit.fraction &&
                (unit.fraction.fractionName == fractionName ||
                 unit.fraction.GetAttitude(myMind.myFraction.fractionName) == attitude)
                )
            {
                return(false);
            }
        }
        return(true);
    }
Esempio n. 5
0
 public virtual Vector2 GetLocation()
 {
     if (addLocation)
     {
         return(addLocation.GetLocation());
     }
     return(Vector2.zero);
 }
Esempio n. 6
0
 private void Update()
 {
     if (autoChooseTarget && locationToFollow)
     {
         selectTarget(locationToFollow.GetLocation(), //autoTargetScale);
                      appliedExternalTarget ? autoTargetScale : 1.0f);
     }//else
      //selectTarget(Camera.main.ScreenToWorldPoint(Input.mousePosition));
 }
Esempio n. 7
0
    public override void EnterAction()
    {
        base.EnterAction();
        var     animator = GetComponentInParent <Animator>();
        Vector2 aimPos   = aim.GetLocation();

        animator.SetFloat("aimX", aimPos.x);
        animator.SetFloat("aimY", aimPos.y);
        animator.SetFloat("speed", movementSpeed);
    }
 public override bool PerformAction()
 {
     if (b)
     {
         float distSq = (location.GetLocation() - (Vector2)transform.position).sqrMagnitude;
         if (distSq > minDistance * minDistance && distSq < maxDistance * maxDistance)
         {
             PlayAnimationTrigger();
             b = false;
         }
     }
     return(true);
 }
    public override bool PerformAction()
    {
        Vector2 point = aim.GetLocation();
        Vector2 inf   = (point - new Vector2(movement.transform.position.x, movement.transform.position.z));

        float sqMag = inf.sqrMagnitude;

        inf.Normalize();
        if (sqMag > stopDistance * stopDistance)
        {
            movement.ApplyInfluencePosition(inf * movementSpeed);
        }
        movement.SetRotation(Vector2.Angle(Vector2.up, inf) * (inf.x > 0 ? 1 : -1));

        return(true);
    }
Esempio n. 10
0
    public override bool PerformAction()
    {
        //movement.ApplyInfluencePointRotation(aim.GetLocation(),  rotationSpeed);
        //movement.SetRotationPoint(aim.GetLocation());
        //movement.ApplyInfluencePoint(aim.GetLocation(), movementSpeed, rotationSpeed, stopDistance);

        Vector2 point = aim.GetLocation();
        Vector2 inf   = (point - (Vector2)movement.transform.position);

        float sqMag = inf.sqrMagnitude;

        inf.Normalize();
        if (sqMag > stopDistance * stopDistance)
        {
            movement.ApplyInfluencePosition(inf * movementSpeed);
        }

        movement.ApplyInfluenceRotation(inf * rotationSpeed);

        return(true);
    }