Exemplo n.º 1
0
    /// <summary>
    /// Custom Update Method
    /// </summary>
    public void Update()
    {
        float angle;

        switch (hullState)
        {
        case TankHullState.Rotating:

            accumTime += Time.deltaTime * tank.prop.hullRotationSpeed;
            angle      = hullTransform.eulerAngles.y + 360.0f * Time.deltaTime * tank.prop.hullRotationSpeed * rotDirection;

            hullTransform.localRotation = Quaternion.Euler(new Vector3(0.0f, angle, 0.0f));

            if (accumTime > rotationTotalTime)
            {
                hullTransform.localRotation = endAngleQ;

                if (Vector3.Distance(hullTransform.position, targetPos) < 0.1f)
                {
                    SoundManager.Instance.StopSound(moveSndId);

                    hullState = TankHullState.Idle;
                }
                else
                {
                    startPos  = hullTransform.position;
                    hullState = TankHullState.Moving;
                }
            }

            break;

        case TankHullState.Moving:

            hullTransform.position = hullTransform.position + moveDir * tank.prop.speedMovement * Time.deltaTime;

            // Update the row/col position
            //currentRowCol = Map.Instance.WorldPosToRowCol(hullTransform.position);

            float dis = Vector3.Distance(hullTransform.position, targetPos);
            if (dis > prevDistance)
            {
                SoundManager.Instance.StopSound(moveSndId);

                hullTransform.position = targetPos;
                hullState = TankHullState.Idle;
            }
            else
            {
                prevDistance = dis;
            }
            break;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Rotate all the tank, the specified degrees
    /// </summary>
    public void RotateRel(float angleOfs)
    {
        moveSndId = SoundManager.Instance.PlaySound(SndId.SND_TANK_TURRET_ROTATE);

        accumTime = 0.0f;
        hullState = TankHullState.Rotating;

        float startAngle = Angle.Normalize(hullTransform.localRotation.eulerAngles.y);

        endAngleQ         = Quaternion.Euler(0.0f, Angle.Normalize(startAngle + angleOfs), 0.0f);
        rotDirection      = (angleOfs > 0.0f ? 1.0f : -1.0f);
        rotationTotalTime = (Mathf.Abs(angleOfs) / 360.0f);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Rotate all the tank, to the specified angle (in degrees)
    /// </summary>
    public void RotateAbs(float targetAngle)
    {
        moveSndId = SoundManager.Instance.PlaySound(SndId.SND_TANK_TURRET_ROTATE);

        accumTime = 0.0f;
        hullState = TankHullState.Rotating;

        float startAngle = hullTransform.eulerAngles.y;
        float dif        = Angle.GetClosestAngleDif(startAngle, targetAngle);

        endAngleQ         = Quaternion.Euler(0.0f, Angle.Normalize(targetAngle), 0.0f);
        rotDirection      = (dif > 0.0f ? 1.0f : -1.0f);
        rotationTotalTime = (Mathf.Abs(dif) / 360.0f);
    }
Exemplo n.º 4
0
 /// <summary>
 /// Custom Start Method
 /// </summary>
 public void Start()
 {
     hullState = TankHullState.Idle;
 }