Example #1
0
    void Update()
    {
        UpdateAnimatorState();
        var closeToCellCenter = UpdateCell();

        if (!Snapping && closeToCellCenter && this.commitedToMovement)
        {
            this.commitedToMovement = false;

            if (this.scheduledStop)
            {
                this.scheduledStop = false;
                Stop();
                return;
            }
        }
        if (this.movingDirection.HasValue)
        {
            if (closeToCellCenter && IsBlockedTorwards(this.movingDirection))
            {
                Stop();
                this.MovementBlocked = true;
                return;
            }
            var vector = CharMovement.GetDirectionVector(this.movingDirection.Value);
            this.transform.position += vector * WalkSpeed * Time.deltaTime;
            var normalizedInt     = new Vector2Int(Mathf.RoundToInt(vector.x), Mathf.RoundToInt(vector.y));
            var nextCellPosition  = this.grid.GetCellPosition(this.cell + normalizedInt);
            var missingToNextCell = nextCellPosition - Position;
            if (missingToNextCell.magnitude / this.grid.cellSize < 1f - MOVEMENT_COMMITMENT_PERCENT)
            {
                this.commitedToMovement = true;
            }
        }
    }
Example #2
0
    public PremadeAnimation RunKnockback(CharMovement.Direction charDirection)
    {
        var forward   = CharMovement.GetDirectionVector(charDirection);
        var backwards = new Vector3(-forward.x, -forward.y, -forward.z);

        return(new AnimationChain(this, new List <PremadeAnimation> {
            new TranslateAnimation(this, backwards * DISTANCE, duration: DURATION / 2f),
            new TranslateAnimation(this, forward * DISTANCE, duration: DURATION / 2f)
        }).Start());
    }
Example #3
0
    void Update()
    {
        if (this.grid == null)
        {
            return;
        }
        this.transform.position += CharMovement.GetDirectionVector(direction) * SPEED * Time.deltaTime;
        var p    = this.transform.position;
        var cell = this.grid.GetCellToSnap(this.transform.position);

        this.transform.position = new Vector3(p.x, p.y, 100 + cell.y);
    }