Esempio n. 1
0
        private void ThrowMe()
        {
            aus.Play();
            if (m_window != null && m_isAiming)
            {
                m_isJumping = true;
                m_isAiming  = false;
                InputLayout = InputHandler.Layout.None;
                var angle = TurnToSide == Side.Left ? 180 - m_aimAngle : m_aimAngle;
                var force = Quaternion.Euler(0, 0, angle) * Vector2.right * m_aimStrength;
                m_rigidBody.AddForce(force, ForceMode2D.Impulse);
                transform.position     += new Vector3(0, 0.5f);
                m_rigidBody.constraints = RigidbodyConstraints2D.None;
                //m_collider.enabled = false;
                //DOVirtual.DelayedCall(0.15f, () => m_collider.enabled = true);
                m_rigidBody.AddForceAtPosition(force / 50, m_rigidBody.position + new Vector2(0, 0.8f));
                //m_collider.size = new Vector2(0.5f, 0.5f);
                m_animator.SetBool("isJumping", true);
                m_window = null;

                // unparent from building:
                transform.SetParent(null);
            }
            if (m_ui != null)
            {
                m_ui.DeactivateAim(this);
            }
        }
Esempio n. 2
0
        private void FixedUpdate()
        {
            if (transform.position.y < -50)
            {
                Destroy(gameObject);
                return;
            }
            Velocity = 0;
            if (m_inputHandler != null && m_inputBlocked == false)
            {
                var dt     = Time.fixedDeltaTime;
                var action = m_inputHandler.Action;
                if (action != m_lastAction)
                {
                    m_lastAction = action;
                    if (m_pickedUp != null && m_pickedUp.IsPickedUp)
                    {
                        if (action)
                        {
                            Aim();
                        }
                        else
                        {
                            Throw();
                        }
                    }
                    else if (m_window == null && action)
                    {
                        m_window = GetInteractible <WindowJumpSite>();
                        if (m_window != null)
                        {
                            AimMe();
                        }
                    }
                    else if (m_window != null && !action)
                    {
                        ThrowMe();
                    }
                }
                if (m_isAiming)
                {
                    if (m_inputHandler.Up)
                    {
                        m_aimStrength = Mathf.Clamp(
                            m_aimStrength + dt * m_aimingStrengthSpeed,
                            m_aimStrengthRange.x,
                            m_aimStrengthRange.y
                            );
                    }
                    else if (m_inputHandler.Down)
                    {
                        m_aimStrength = Mathf.Clamp(
                            m_aimStrength - dt * m_aimingStrengthSpeed,
                            m_aimStrengthRange.x,
                            m_aimStrengthRange.y
                            );
                    }
                    if (TurnToSide == Side.Left)
                    {
                        if (m_inputHandler.Right)
                        {
                            m_aimAngle += m_aimingAngleSpeed * dt;
                        }
                        else if (m_inputHandler.Left)
                        {
                            m_aimAngle -= m_aimingAngleSpeed * dt;
                        }
                    }
                    else
                    {
                        if (m_inputHandler.Left)
                        {
                            m_aimAngle += m_aimingAngleSpeed * dt;
                        }
                        else if (m_inputHandler.Right)
                        {
                            m_aimAngle -= m_aimingAngleSpeed * dt;
                        }
                    }
                }
                else
                {
                    var up   = m_inputHandler.Up;
                    var down = m_inputHandler.Down;
                    if (up != m_lastUp)
                    {
                        m_lastUp = up;
                        if (up)
                        {
                            if (!PickUp() && m_isNearPortal && m_canTeleportUp)
                            {
                                TeleportUp();
                            }
                        }
                    }
                    else if (down != m_lastDown)
                    {
                        m_lastDown = down;
                        if (down)
                        {
                            if (m_isNearPortal && m_canTeleportDown)
                            {
                                TeleportDown();
                            }
                            else
                            {
                                PutDown();
                            }
                        }
                    }
                    if (m_inputHandler.Left)
                    {
                        //m_rigidBody.AddForce((Vector2.left * m_speed + Vector2.up) * dt * m_rigidBody.mass, ForceMode2D.Impulse);
                        m_rigidBody.MovePosition(m_rigidBody.position + (Vector2.left + smallOffsetY) * m_speed * dt);
                        Velocity   = -m_speed;
                        TurnToSide = Side.Left;
                    }
                    else if (m_inputHandler.Right)
                    {
                        //m_rigidBody.AddForce((Vector2.right * m_speed + Vector2.up) * dt * m_rigidBody.mass, ForceMode2D.Impulse);
                        m_rigidBody.MovePosition(m_rigidBody.position + (Vector2.right + smallOffsetY) * m_speed * dt);
                        Velocity   = m_speed;
                        TurnToSide = Side.Right;
                    }
                }
            }

            var handPos = m_pickableOrigin == null ? transform.position : m_pickableOrigin.position;

            if (m_pickedUp != null && m_pickedUp.IsPickedUp)
            {
                m_pickedUp.transform.position = handPos;
            }
            if (m_pickedUp != null && m_pickedUp.IsPickedUp && m_ui != null)
            {
                m_ui.UpdateAim(
                    this,
                    handPos,
                    TurnToSide == Side.Left ? 180 - m_aimAngle : m_aimAngle,
                    m_aimStrength
                    );
            }
            else if (m_window != null && m_ui != null)
            {
                m_ui.UpdateAim(
                    this,
                    handPos,
                    TurnToSide == Side.Left ? 180 - m_aimAngle : m_aimAngle,
                    m_aimStrength
                    );
            }
            if (m_isJumping == true && m_rigidBody.velocity.magnitude < 0.1f)
            {
                m_animator.SetBool("isJumping", false);
                m_rigidBody.freezeRotation = true;
                transform.localRotation    = Quaternion.identity;
                m_isJumping                         = false;
                m_inputBlocked                      = false;
                m_inputHandler.InputLayout          = cachedLayout;
                GetComponent <BoxCollider2D>().size = new Vector2(1, 2);
            }
        }