Ejemplo n.º 1
0
    public override void Init(ETileObjectType type, int x, int y, string[] args)
    {
        base.Init(type, x, y, args);
        EFacingDirection playerFacingDirection = (EFacingDirection)Enum.Parse(typeof(EFacingDirection), (String)args.GetValue(0), true);

        GetComponent <PlayerController> ().SetFacingDirection(playerFacingDirection);
    }
Ejemplo n.º 2
0
    public override void Init(ETileObjectType type, int x, int y, string[] args)
    {
        base.Init(type, x, y, args);
        EFacingDirection wallOrientation = (EFacingDirection)Enum.Parse(typeof(EFacingDirection), (String)args.GetValue(0), true);

        GetComponent <SpriteRenderer> ().sprite = RessourceManager.LoadSprite(args[1], 0);
        transform.rotation = Quaternion.Euler(new Vector3(0, 0, PlayerController.ms_FacingAngles[wallOrientation]));
    }
Ejemplo n.º 3
0
    void SetFacingDirection(EFacingDirection _eFacingDirection)
    {
        if (m_eFacingDirection != _eFacingDirection)
        {
            m_eFacingDirection = _eFacingDirection;


            if (FacingDirectionChangeSubscribers != null)
            {
                FacingDirectionChangeSubscribers(m_eFacingDirection);
            }


            Debug.Log("Facing Direction: " + _eFacingDirection.ToString());
        }
    }
Ejemplo n.º 4
0
    private int TurnInternal(int directionToFace)
    {
        m_OldAngle = transform.rotation.eulerAngles;

        if ((int)m_FacingDirection == Modulo(directionToFace + 1, 4))
        {
            m_TargetAngle     = transform.rotation.eulerAngles + new Vector3(0, 0, 90);
            m_FacingDirection = (EFacingDirection)directionToFace;
            return(-1);
        }
        else if ((int)m_FacingDirection == Modulo(directionToFace - 1, 4))
        {
            m_TargetAngle     = transform.rotation.eulerAngles + new Vector3(0, 0, -90);
            m_FacingDirection = (EFacingDirection)directionToFace;
            return(1);
        }
        return(0);
    }
Ejemplo n.º 5
0
    public void UpdateFacing(float dt)
    {
        float yaw = PlaneContainer.transform.localRotation.eulerAngles.y;

        if (currentVelocity.magnitude > 0)
        {
            facingDirection = currentVelocity.x < 0 ? EFacingDirection.Left : EFacingDirection.Right;
        }

        float targetYaw = (facingDirection == EFacingDirection.Left) ? -180 : 0;

        //if(facingDirection == EFacingDirection.Left)
        //{

        //    yaw -= rotationSpeed * dt;
        //    targetYaw = -180f;
        //}
        //else
        //{
        //    yaw += rotationSpeed * dt;
        //    targetYaw = 0f;
        //}

        yaw = Mathf.LerpAngle(yaw, targetYaw, rotationSpeed);
        if (Mathf.Approximately(yaw, targetYaw))
        {
            yaw = targetYaw;
        }


        //if(yaw > -180 && yaw < 0)
        // {
        //if (facingDirection == EFacingDirection.Left)
        //{
        //    yaw = Mathf.Max(yaw - RotationSpeed * dt, -180);
        //}
        //else
        //{
        //    yaw = Mathf.Min(yaw + RotationSpeed * dt, 0);
        //}
        PlaneContainer.transform.localRotation = Quaternion.Euler(0f, yaw, 0f);
        //}
    }
Ejemplo n.º 6
0
    void Update()
    {
        if (!IsAlive)
        {
            return;
        }

        if ((_characterController.collisionFlags & CollisionFlags.Sides) != 0)
        {
            _currentSpeed = 0;
        }

        if ((_characterController.collisionFlags & CollisionFlags.Below) != 0)
        {
            _amountToMove.y = -1f;
            _totalJumps     = 0;

            _animator.SetBool("Is Grounded", true);
        }
        else
        {
            _amountToMove.y -= gravity * Time.deltaTime;
            _animator.SetBool("Is Grounded", false);
        }

        if (Input.GetButtonDown("Jump") && _totalJumps < jumpsAllowed)
        {
            Jump();
        }

        float targetSpeed = Input.GetAxisRaw("Horizontal") * runSpeed;

        _currentSpeed = IncrementTowards(_currentSpeed, targetSpeed, acceleration);

        if (transform.position.z != 0)
        {
            _amountToMove.z = -transform.position.z;
        }

        _amountToMove.x = _currentSpeed;

        //if (_amountToMove.x != 0)
        //    body.localScale = new Vector2(Mathf.Sign(_amountToMove.x) * Mathf.Abs(body.localScale.x), body.localScale.y);

        UpdateOrientation();

        if (_amountToMove.x != 0.0f)
        {
            Direction = Mathf.Sign(_amountToMove.x);
        }

        _characterController.Move(_amountToMove * Time.deltaTime);

        _animator.SetBool("Is Moving", _amountToMove.x != 0.0f);

        if (_amountToMove.x != 0)
        {
            FacingDirection          = (EFacingDirection)((int)Mathf.Sign(_amountToMove.x));
            _lastHorizontalDirection = FacingDirection;
        }
        if (Input.GetAxisRaw("Vertical") > 0f)
        {
            FacingDirection = EFacingDirection.Up;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            FireWeapon();
        }
    }
Ejemplo n.º 7
0
 public void SetFacingDirection(EFacingDirection newFacingOrientation)
 {
     m_FacingDirection  = newFacingOrientation;
     transform.rotation = Quaternion.Euler(0, 0, ms_FacingAngles[newFacingOrientation]);
 }