Ejemplo n.º 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);
    }
Ejemplo n.º 2
0
    private void UpdateStateMachine()
    {
        int result = _stateMachine.Tick();

        IState state = _stateMachine.currentState;

        if (state is UnitStateIdle)
        {
        }
        else if (state is UnitStateDead)
        {
        }
        else if (state is UnitStateFighting)
        {
        }
        else if (state is UnitStateEntering)
        {
            if (result == (int)UnitStateEntering.RESULT.DONE)
            {
            }
        }
        else if (state is UnitStateFire)
        {
            if (result == (int)UnitStateFire.RESULT.DONE)
            {
                _stateMachine.Change(new UnitStateFighting(this));
            }
        }

        if (unit.dataUnit.bodyType == DataConfig.BODY_TYPE.CAR_WITH_CANNON)
        {
            if (_unitDriver.engine.IsStopped())
            {
                float speed             = AIMMING_ROTATE_SPEED;
                AimmingControl.RESULT r = AimmingControl.Rotate(
                    body.transform.rotation.eulerAngles.y,
                    launcher.transform.rotation.eulerAngles.y,
                    speed,
                    0.01f);
                body.transform.Rotate(new Vector3(0, r.turnDegree, 0));
            }
            else
            {
                launcher.transform.rotation = body.transform.rotation;
            }
        }
    }