Пример #1
0
    private bool Move()
    {
        speed += ACCELERATE * TimeHelper.deltaTime;
        speed  = Mathf.Min(speed, SPEED_MAX);

        float rotSpeed = speed / SPEED_MAX * SPEED_ROTATE;


        Vector3 destination = GetCurrentDestination();

        AimmingControl.RESULT rotateR = AimmingControl.Rotate(
            transform.position, destination, transform.rotation.eulerAngles.y, rotSpeed, 0.01f);
        transform.Rotate(new Vector3(0, rotateR.turnDegree, 0));


        Vector3 line = destination - transform.position;
        float   dist = line.magnitude;

        Vector3 orientation = UnitHelper.GetOrientation(transform);

        VectorHelper.ResizeVector(ref orientation, dist);
        Vector3 p = orientation + transform.position;

        float radius = _shoot.target.unit.dataUnit.GetHurtRadius();

        MovingControl.RESULT moveR = MovingControl.MoveTo(transform.position, p, speed, radius + heightInitOffset);
        transform.position = moveR.destination;


        return(moveR.arrived);
    }
Пример #2
0
    private void MoveForward()
    {
        Vector3 orientation = UnitHelper.GetOrientation(_body.transform);

        VectorHelper.ResizeVector(ref orientation, 10);

        Vector3 targetPosition = _owner.transform.position + orientation;

        MovingControl.RESULT r = Move(targetPosition, true);
    }
Пример #3
0
    private void MoveWithPath()
    {
        UpdateTurning(_shortPath.targetTileCenter);

        MovingControl.RESULT r = Move(_shortPath.targetTileCenter, true);
        if (r.blocked)
        {
            FindPathToTargetPosition();
        }
    }
Пример #4
0
    // ==================================================================
    // algorithm

    private MovingControl.RESULT Move(Vector3 targetPosition, bool testCollision)
    {
        float   moveDist;
        float   dist;
        float   speed       = _speed * _engine.speedScale;
        Vector3 orientation = UnitHelper.GetOrientation(_body.transform);
        Vector3 destination = MovingControl.CalcDestinationWithOrientation(_owner.transform.position, targetPosition, speed, orientation,
                                                                           out moveDist, out dist);

        if (testCollision)
        {
            UnitCollisionDetector.RESULT cr =
                _unit.collisionDetector.Detect_withOrientationTest(destination);
            if (cr != null)
            {
                MovingControl.RESULT r = new MovingControl.RESULT();
                r.blocked = true;
                r.arrived = false;
                return(r);
            }
        }

        bool isBlocked = IsDestinationBlocked(destination);

        if (isBlocked)
        {
            MovingControl.RESULT r = new MovingControl.RESULT();
            r.blocked = true;
            r.arrived = false;
            return(r);
        }
        else
        {
            _owner.transform.position = destination;

            MovingControl.RESULT r = new MovingControl.RESULT();
            r.distance     = moveDist;
            r.distanceLeft = dist - moveDist;
            r.destination  = destination;
            r.arrived      = (r.distanceLeft <= 0.01f);
            return(r);
        }
    }
Пример #5
0
    private void MoveDirectly()
    {
        UpdateTurning(_targetPosition);

        MovingControl.RESULT r = Move(_targetPosition, true);
    }