Ejemplo n.º 1
0
        private void calcInterpolatedPosition(float delta)
        {
            if (positions.Count > 0 && nextPosition == null)
            {
                nextPosition = positions.Dequeue();
                isRunning    = nextPosition.isRunning;
                direction    = nextPosition.direction;
            }

            if (nextPosition != null)
            {
                float baseTimeBetweenPoints = 1.0f / 30.0f;
                float ratioToProcess        = (delta / baseTimeBetweenPoints) * (positions.Count / INTERPOLATION_MIDDLE_NUMBER);

                float moveSpeed = Stats.CHARACTER_SPEED;

                currentInterpolationTime += ratioToProcess;

                while (true)
                {
                    Vector2 directionVector     = getDirectionVector(direction);
                    Vector2 directionNormalized = directionVector.normalized;
                    Vector2 velocityVector      = directionNormalized * moveSpeed * delta * ratioToProcess;

                    if (currentInterpolationTime >= 1)
                    {
                        setPosition(new Vector2(nextPosition.position.X, nextPosition.position.Y));

                        if (positions.Count > 0)
                        {
                            nextPosition              = positions.Dequeue();
                            direction                 = nextPosition.direction;
                            isRunning                 = nextPosition.isRunning;
                            currentInterpolationTime -= 1;
                            ratioToProcess            = currentInterpolationTime;
                            continue;
                        }
                        else
                        {
                            currentInterpolationTime = 0;
                            nextPosition             = null;
                            break;
                        }
                    }
                    else
                    {
                        setPosition(transform.position + new Vector3(velocityVector.x, velocityVector.y, 0));
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public override void updateState(CharacterPositionUpdate characterUpdate)
 {
     // Do nothing
 }
Ejemplo n.º 3
0
        //protected abstract void calculateVelocityVectorAndDirection(float delta);

        public abstract void updateState(CharacterPositionUpdate characterUpdate);
Ejemplo n.º 4
0
 public override void updateState(CharacterPositionUpdate characterUpdate)
 {
     positions.Enqueue(characterUpdate);
 }