예제 #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 targPos      = transform.position;
        Vector2 _viewportPos = Camera.main.WorldToViewportPoint(_player.position);

        if (_dialogue.IsTalking() || _viewportPos.x > 0.7f || _viewportPos.x < 0.3f)
        {
            targPos.x = _player.position.x;
        }
        transform.position = Vector3.SmoothDamp(transform.position, targPos, ref _vel, _dialogue.IsTalking() ? 0.2f : _speed);
    }
예제 #2
0
    private void Animate()
    {
        string face = "Idle";

        //on move
        if (_inputMovement != Vector3.zero)
        {
            //do legs
            if (Time.frameCount % (_run ? 4 : 8) == 0)
            {
                _legs.UpdateLegs(_inputMovement);
            }

            //bob sprite
            float runMultiplier = _run ? 2 : 1;
            _sprite.localPosition    = _startPosSprite + Vector3.up * (_bobAmplitude * Mathf.Sin(Time.frameCount * (_bobFrequency * runMultiplier)));
            _sprite.localEulerAngles = Vector3.forward * _bobAngle * Mathf.Sin(Time.frameCount * ((_bobFrequency / 2) * runMultiplier));

            //move face
            _face.transform.localPosition = Vector3.Lerp(_face.transform.localPosition, _faceStartPos + (new Vector3(_inputMovement.x, _inputMovement.z / 2).normalized * 0.05f), 0.2f);

            //change face
            if (_inputMovement.x != 0)
            {
                face = _inputMovement.x > 0 ? "Right" : "Left";
            }
            else
            {
                face = "Idle";
            }
        }
        else
        {
            _face.transform.localPosition = _faceStartPos;
        }

        //dialogue talking
        if (_dialogue.IsTalking())
        {
            face = "Talk";
        }

        //change face
        _face.ChangeFace(face);
    }