예제 #1
0
    public override void Tick()
    {
        if (target_InputController != null)
        {
            int snap = itemWithSnap != null ? itemWithSnap.angleSnap : 1;

            Vector3 lookdir   = ShadyMath.AngleSnap(target_InputController.transform.position - inputController.transform.position, snap);
            Vector2 lineStart = target_InputController.transform.position + (-lookdir * targetDistance.y);
            Vector2 lineEnd   = target_InputController.transform.position + (-lookdir * targetDistance.x);

            desiredPos = ShadyMath.NearestPointOnFiniteLine(lineStart, lineEnd, inputController.transform.position);

            if (debugObj != null)
            {
                debugObj.position = desiredPos;
            }

            float dst = Vector2.Distance(inputController.transform.position, desiredPos);
            if (dst > errorThreshold)
            {
                agent.AddSteeringForce(agent.Seek(desiredPos), priority);
            }

            else if (exitStateOnAlign)
            {
                Next();
            }
        }
    }
예제 #2
0
    public override void Tick()
    {
        if (exitStateProjectileDestroyed && projectileRef == null)
        {
            Next();
            return;
        }

        if (target_InputController != null)
        {
            Vector3 lookdir = projectileRef.transform.position - target_InputController.transform.position;
            lookdir.Normalize();


            Vector2 lineStart  = target_InputController.transform.position + (-lookdir * .5f);
            Vector2 lineEnd    = target_InputController.transform.position + (-lookdir * 10f);
            var     desiredPos = ShadyMath.NearestPointOnFiniteLine(target_InputController.transform.position, lineEnd, inputController.transform.position);

            if (debugObj != null)
            {
                debugObj.position = desiredPos;
            }

            float dst = Vector2.Distance(lineStart, desiredPos);
            if (dst <= trackingDistance && dst > errorThreshold)
            {
                agent.AddSteeringForce(agent.Seek(desiredPos), priority);
            }
        }
    }