Exemple #1
0
    void FixedUpdate()
    {
        //двигаем пушку
        if (isMoving)
        {
            rb.MovePosition(Vector2.Lerp(rb.position, pos, CannonSpeed * Time.fixedDeltaTime));
        }
        //не двигаем
        else
        {
            rb.velocity = Vector2.zero;
        }

        //вращаем колеса при движении
        velocityX = rb.GetPointVelocity(rb.position).x;
        if (Mathf.Abs(velocityX) > 0.0f && Mathf.Abs(rb.position.x) < screenBounds)
        {
            motor.motorSpeed = velocityX * 150f;
            MotorActivate(true);
        }
        //останавливаем вращение колес
        else
        {
            motor.motorSpeed = 0f;
            MotorActivate(false);
        }
    }
Exemple #2
0
        private void FixedUpdate()
        {
            isGrounded = false;
            Ray2D        ray = new Ray2D(transform.position, -transform.up);
            RaycastHit2D hit = Physics2D.Raycast(transform.position, -transform.up, radius + suspensionLen,
                                                 LayerMask.GetMask("Ground"));

            if (hit.collider != null)
            {
                lastSpringCompression = springCompression;
                springCompression     = radius + suspensionLen - hit.distance;
                float relativeVelocity = (springCompression - lastSpringCompression) / Time.fixedDeltaTime;
                float suspensionForce  = stiffness * springCompression + damper * relativeVelocity;
                _wheelVelocity = transform.InverseTransformDirection(rbody.GetPointVelocity(hit.point));
                float forwardDriveForce = throttleSpeed * suspensionForce;

                float forwardFriction = (_wheelVelocity.x + transform.up.x) * suspensionForce;
                print(forwardFriction);
                forwardDriveForce -= brakeForce;

                Vector3 resultantForce = transform.up * suspensionForce +
                                         transform.right * (forwardDriveForce - forwardFriction);


                rbody.AddForceAtPosition(resultantForce, hit.point);
                isGrounded = true;
            }
        }
Exemple #3
0
    void FixedUpdate()
    {
        //Move the cannon
        if (isMoving)
        {
            rb.MovePosition(Vector2.Lerp(rb.position, pos, CannonSpeed * Time.fixedDeltaTime));
        }
        else
        {
            rb.velocity = Vector2.zero;
        }

        //Rotate wheels
        velocityX = rb.GetPointVelocity(rb.position).x;
        if (Mathf.Abs(velocityX) > 0.0f && Mathf.Abs(rb.position.x) < screenBounds)
        {
            motor.motorSpeed = velocityX * 150f;
            MotorActivate(true);
        }
        else
        {
            motor.motorSpeed = 0f;
            MotorActivate(false);
        }
    }
 public override Vector2 GetPointVelocity(Vector2 point)
 {
     if (!HasRigidbody())
     {
         return(Vector2.zero);
     }
     return(rigidbody.GetPointVelocity(point));
 }
        protected Vector3 ReferenceRigidbodyDisplacement(Vector3 position, Rigidbody2D referenceRigidbody, float dt)
        {
            if (referenceRigidbody == null)
            {
                return(Vector3.zero);
            }

            return(ReferenceRigidbodyDisplacement(position, (Vector3)referenceRigidbody.GetPointVelocity(position), (Vector3)referenceRigidbody.position, dt));
        }
Exemple #6
0
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.W))
        {
            if (transform.localScale.y == 1)
            {
                rb.AddTorque(-1f * torque);
            }
            else if (transform.localScale.y == -1)
            {
                rb.AddTorque(1f * torque);
            }
        }

        if (Input.GetKey(KeyCode.S))
        {
            if (transform.localScale.y == 1)
            {
                rb.AddTorque(1f * torque);
            }
            else if (transform.localScale.y == -1)
            {
                rb.AddTorque(-1f * torque);
            }
        }


        /*
         * lift = rb.velocity.x * speed *0.05f;
         * if (lift > 10f) {
         *      lift = 10f;
         * }
         * rb.AddRelativeForce (Vector2.up * lift); */

        Vector3 targetVelocity = transform.forward * speed;

        //rb.AddForceAtPosition (targetVelocity, engine.position);
        rb.AddRelativeForce(Vector2.right * speed);



        Vector2 velocity  = rb.GetPointVelocity(transform.position);
        float   speedy    = velocity.magnitude;
        Vector2 direction = velocity.normalized;
        Vector2 worldNrm  = transform.up;

        if (Vector2.Dot(worldNrm, direction) < 0)
        {
            worldNrm = -worldNrm;
        }

        float   angle = 1f - Mathf.Clamp((Vector2.Angle(worldNrm, direction) / 90f), 0, 1f);
        Vector2 drag  = -worldNrm * angle * speedy * speedy * lift;


        rb.AddForceAtPosition(drag * Time.fixedDeltaTime, transform.position);
    }
        // Use this for calculate
        public override void OnCalculate()
        {
            Rigidbody2D rigidbody2D = _Rigidbody2D.value;

            if (rigidbody2D != null)
            {
                _Result.SetValue(rigidbody2D.GetPointVelocity(_Point.value));
            }
        }
Exemple #8
0
    static int GetPointVelocity(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Rigidbody2D obj  = LuaScriptMgr.GetNetObject <Rigidbody2D>(L, 1);
        Vector2     arg0 = LuaScriptMgr.GetNetObject <Vector2>(L, 2);
        Vector2     o    = obj.GetPointVelocity(arg0);

        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 direct = transform.parent.TransformPoint(defaultPos) - transform.position;

        rb.AddForce(direct * force);
        Vector2 pointVel = parent.GetPointVelocity(parent.transform.TransformPoint(defaultPos));
        Vector2 extraVel = rb.velocity - pointVel;

        extraVel   *= damp;
        rb.velocity = pointVel + extraVel;
    }
Exemple #10
0
    private void Shoot()
    {
        var pos = _transform.position + _transform.forward * 1.2f;

        pos.z = 0.5f;
        var rot            = _transform.rotation;
        var projectile     = PhotonNetwork.Instantiate(_projectilePrefab.name, pos, rot);
        var projectileBody = projectile.GetComponent <Rigidbody2D>();

        projectileBody.velocity = _body.GetPointVelocity(pos);
    }
 void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
 {
     Debug.Log("PointerDown");
     if (!isTouching)
     {
         isTouching                      = true;
         pointerID                       = eventData.pointerId;
         origin                          = eventData.position;
         touchedPos                      = Camera.main.ScreenToWorldPoint(new Vector3(eventData.position.x, eventData.position.y, 30.2f));
         touchedPos2D.x                  = touchedPos.x;
         touchedPos2D.y                  = touchedPos.y;
         touchedPos2D                    = Restrict(touchedPos2D);
         rigidbody2Move.isKinematic      = true;
         rigidbody2Move.gameObject.layer = LayerName.MovingMoon;
         rigidbody2Move.position         = (touchedPos2D);
         rigidbody2Move.velocity         = Vector2.zero;
         rigidbody2Move.angularVelocity  = 0;
         rigidbody2Move.gravityScale     = 0.0f;
         lastVelocity                    = rigidbody2Move.GetPointVelocity(touchedPos2D);
         recentVelocities                = pushValue(recentVelocities, lastVelocity);
     }
 }
    private void FixedUpdate()
    {
        if (onGroundSentinel && Input.GetButton("Jump"))
        {
            onGroundSentinel = false;
            timeJumping      = Time.time;
            jumpingSentinel  = true;
        }
        float   xMove  = Input.GetAxis("Horizontal");
        Vector2 vxMove = new Vector2(xMove, 0.0F);

        if (!Input.GetButton("Jump"))
        {
            jumpingSentinel = false;
        }
        if (timeBouncing + maxBouncing < Time.time)
        {
            bounceSentinel = false;
        }
        if (!bounceSentinel)
        {
            if (onGroundSentinel)
            {
                rb.AddForce(vxMove * impulse);
                rb.AddForce(Vector2.right * rb.GetPointVelocity(this.transform.position) * -retard);
            }
            else
            {
                rb.AddForce(vxMove * impulse * retardOnAir);
                rb.AddForce(Vector2.right * rb.GetPointVelocity(this.transform.position) * -retard * retardOnAir);
            }
            if ((jumpingSentinel || timeJumping + minJump > Time.time) && !(timeJumping + maxJump < Time.time))
            {
                rb.AddForce(Vector2.up * jumpImpulse * rb.gravityScale);
            }
        }
    }
Exemple #13
0
        /// <summary>
        /// Sets all the structs fields, based on the callback ("enter" or "stay") and the 2D contact.
        /// </summary>
        public void Set(bool firstContact, ContactPoint2D contact)
        {
            this.firstContact = firstContact;
            this.collider2D   = contact.collider;
            this.point        = contact.point;
            this.normal       = contact.normal;
            this.gameObject   = this.collider2D.gameObject;

            Rigidbody2D contactRigidbody = this.collider2D.attachedRigidbody;

            if (this.isRigidbody = contactRigidbody != null)
            {
                this.isKinematicRigidbody = contactRigidbody.isKinematic;
                this.pointVelocity        = contactRigidbody.GetPointVelocity(this.point);
            }
        }
Exemple #14
0
        private void OnCollisionEnter2D(Collision2D collision)
        {
            if (_rigidbody2D.IsNull() || IsDestroyed)
            {
                return;
            }
            if (_rigidbody2D.IsNotNull() && _freezeRigidbodyUntilCollision)
            {
                _rigidbody2D.isKinematic = false;
            }
            var impactVelocity = _rigidbody2D.GetPointVelocity(collision.contacts.First().point);

            if (_breakByForce && impactVelocity.magnitude >= _impactVelocityToBreak)
            {
                Destroyed.SafelyInvoke(this);
            }
        }
    // Update is called once per frame
    void Update()
    {
        Vector2 motionVec = rigidbody2d.GetPointVelocity(this.transform.position);
        bool    right     = motionVec.normalized.x > 0;

        if (motionVec == Vector2.zero)
        {
            return;
        }
        float angle = Vector2.Angle(Vector2.up, motionVec);

        if (right)
        {
            angle = -angle;
        }
        transform.rotation = Quaternion.Euler(0, 0, angle);
    }
Exemple #16
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 velocity  = plane.GetPointVelocity(transform.position);
        float   speed     = velocity.magnitude;
        Vector2 direction = velocity.normalized;
        Vector2 worldNrm  = transform.up;

        if (Vector2.Dot(worldNrm, direction) < 0)
        {
            worldNrm = -worldNrm;
        }

        float   angle = 1f - Mathf.Clamp((Vector2.Angle(worldNrm, direction) / 90f), 0, 1f);
        Vector2 drag  = -worldNrm * angle * speed * speed * lift;

        if (debug)
        {
            Debug.DrawRay(transform.position, drag, Color.green);
            Debug.Log(angle);
        }
        plane.AddForceAtPosition(drag * Time.fixedDeltaTime, transform.position);
    }
Exemple #17
0
    private void FixedUpdate()
    {
        if (isMoving)
        {
            rigidBody.MovePosition(Vector2.Lerp(rigidBody.position, mousePosition, CannonSpeed * Time.fixedDeltaTime));
        }
        else
        {
            rigidBody.velocity = Vector2.zero;
        }

        velocityX = rigidBody.GetPointVelocity(rigidBody.position).x;

        if (Mathf.Abs(velocityX) > 0.0f && Mathf.Abs(rigidBody.position.x) < screenBounds)
        {
            motor.motorSpeed = velocityX * 150f;
            MotorActivate(true);
        }
        else
        {
            motor.motorSpeed = 0f;
            MotorActivate(false);
        }
    }
    private void FixedUpdate()
    {
        if (ismoving)
        {
            _rigidbody2D.MovePosition(Vector2.Lerp(_rigidbody2D.position, _pos, _canonSpeed * Time.deltaTime));
        }
        else
        {
            _rigidbody2D.velocity = Vector2.zero;
        }

        _xVelocity = _rigidbody2D.GetPointVelocity(_rigidbody2D.position).x;

        if (Mathf.Abs(_xVelocity) > 0.0f && Mathf.Abs(_rigidbody2D.position.x) < _screenBounds)
        {
            _motor.motorSpeed = _xVelocity * 150f;
            MotorActivated(true);
        }
        else
        {
            _motor.motorSpeed = 0f;
            MotorActivated(false);
        }
    }
Exemple #19
0
    // Update is called once per frame
    void Update()
    {
        if (Random.value < changeDirectionProbability && canChange)
        {
            canChange = false;
            Invoke("ChangeDirection", 1f);
        }
        Vector3 dir = sipnClockwise ? Vector3.back : Vector3.forward;
        var     vel = myRigidBody.GetPointVelocity(new Vector2(2, 2));

        if ((sipnClockwise && vel.y < maxSpeed))
        {
            myRigidBody.AddTorque(speed);
        }
        else if ((!sipnClockwise && vel.y > -maxSpeed))
        {
            myRigidBody.AddTorque(-speed);
        }
        else
        {
            myRigidBody.AddTorque(sipnClockwise ? -speed : speed);
            ChangeDirection();
        }
    }
Exemple #20
0
    public void releaseEquipKey()
    {
        equipKeyDown = false;
        float currRotation = playerRB.rotation;

        rotationDiff = currRotation - prevPrevRotation;
        if (justPickedUpWeapon)
        {
            justPickedUpWeapon = false;
        }
        else if (hasWeapon)
        {
            // if you already have a weapon, throw it away
            hasWeapon = false;
            if (this.name == "Player1")
            {
                tutKeyManager.P1EquipPressed();
            }
            else if (this.name == "Player2")
            {
                tutKeyManager.P2EquipPressed();
            }
            foreach (Transform childTrans in this.transform)
            {
                if (childTrans.CompareTag("Weapon") || childTrans.CompareTag("SoftWeapon"))
                {
                    // throw weapon away
                    childTrans.SetParent(listOfWeapons.transform);
                    Rigidbody2D childRB = childTrans.gameObject.AddComponent <Rigidbody2D>();

                    Vector3 weaponPos = childTrans.position;
                    weaponPos.z         = 30;
                    childTrans.position = weaponPos;

                    childRB.gravityScale = 0;
                    childRB.drag         = 0.75f;
                    childRB.angularDrag  = 1;
                    Vector2 throwVelocity = playerRB.GetPointVelocity(childTrans.position) * 2f;
                    // also need to take into account player rotation velocity
                    float velX = 0;
                    float velY = 0;
                    if (rotationDiff > 0)
                    {
                        // counterclockwise fling
                        velX = Mathf.Cos((prevRotation + 90) * DEG_TO_RAD) * rotationDiff * 1.25f;
                        velY = Mathf.Sin((prevRotation + 90) * DEG_TO_RAD) * rotationDiff * 1.25f;
                    }
                    else
                    {
                        // clockwise fling
                        velX = Mathf.Cos((prevRotation - 90) * DEG_TO_RAD) * -rotationDiff * 1.25f;
                        velY = Mathf.Sin((prevRotation - 90) * DEG_TO_RAD) * -rotationDiff * 1.25f;
                    }
                    float aimDirMultiplier = 5 + playerRB.velocity.magnitude * 0.2f;
                    throwVelocity.x += velX - Mathf.Sin(currRotation * Mathf.Deg2Rad) * aimDirMultiplier;
                    throwVelocity.y += velY + Mathf.Cos(currRotation * Mathf.Deg2Rad) * aimDirMultiplier;

                    childTrans.gameObject.GetComponent <Rigidbody2D>().velocity = throwVelocity;
                    childTrans.gameObject.GetComponent <Rigidbody2D>().AddTorque(rotationDiff * 4);
                    break;
                }
            }
            // reset movement multipliers
            currentEngineScript.setWeaponTurnMult(1);
            currentEngineScript.setWeaponMoveMult(1);
            currentWeaponScript.unequipWeaponExtra();
            currentWeaponScript = null;
        }
    }
Exemple #21
0
    // Update is called once per frame
    void Update()

    {
        if (ded)
        {
            deathtimer = Time.time;
            if (deadswitch)
            {
                Physics2D.gravity = new Vector2(0, -9.8f);
                controller.m_Rigidbody2D.velocity = Vector2.zero;
                StopAllMovement();
                if (!mT.iamtheone)
                {
                    mTT.Glasorgel.Stop();
                    mTT.mysteryT.Stop();
                    mTT.mysteryI.Stop();
                }
                else
                {
                    mT.ShutUp();
                }

                deathtimercontrol = Time.time + 11.5f;
                yeetyouded.Play();
                deadswitch = false;
            }
            else if (deathtimer >= deathtimercontrol && deadswitch2)
            {
                deadswitch2 = false;
                yeetdeadandsad.Play();
            }
        }
        if (mainSwitch)
        {
            velocity = _Rigidbody.GetPointVelocity(Vector2.one);
            hmove    = (Input.GetAxisRaw("Horizontal") * speed);
            if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow))
            {
                if (doubleJump)
                {
                    dJumpDelayDelay = false;
                }
                if (doubleJump && dJumpSwitch && dJumpDebugSwitch)
                {
                    dJumpSwitch = false;
                    animator.SetBool("IsJumping", false);
                    animator.SetBool("isAirdash", true);
                    airdash = true;
                    dashA.Play();
                    controller.m_Grounded             = true;
                    controller.m_Rigidbody2D.velocity = Vector2.zero;
                    controller.Move(hmove * Time.fixedDeltaTime, false, true);

                    dJumpDebugSwitch = false;
                }
                else
                {
                    if (!airdash)
                    {
                        animator.SetBool("IsJumping", true);
                    }
                    jump = true;
                    if (dJumpDelaySwitch)
                    {
                        dJumpSwitch      = false;
                        dJumpDelaySwitch = false;
                    }
                }
            }
            if (!dJumpDelaySwitch && dJumpDelay == 0 && (Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp(KeyCode.UpArrow)))
            {
                dJumpDelay  = -1;
                dJumpSwitch = true;
            }
            animator.SetFloat("HeroSpeed", Mathf.Abs(hmove));
            if (!dJumpDelayDelay && dJumpDelay > 0)
            {
                dJumpDelay--;
            }

            if (Input.GetKeyDown(KeyCode.F) && dash && dashswitch)
            {
                dashswitch = false;
                dashaction = true;
                animator.SetBool("IsJumping", false);
                animator.SetBool("isAirdash", true);
                dashN.Play();
                airdash         = true;
                dashactiondelay = true;
            }

            if (gravity)
            {
                if (Input.GetKey(KeyCode.A))
                {
                    if (!rotaA)
                    {
                        GravityM = true;
                        Temple   = false;
                    }
                    controller.m_Rigidbody2D.velocity = Vector2.zero;
                    Physics2D.gravity = new Vector2(-100f, 0);
                    rotaA             = true;
                    rotaD             = false;
                    rotaS             = false;
                    animator.SetBool("mysteryA", true);
                    animator.SetBool("mysteryD", false);
                    animator.SetBool("IsJumping", false);
                }
                if (Input.GetKey(KeyCode.S))
                {
                    if (!rotaS)
                    {
                        GravityM = false;
                        Temple   = true;
                    }
                    Physics2D.gravity = new Vector2(0, -9.8f);
                    rotaA             = false;
                    rotaD             = false;
                    rotaS             = true;
                    animator.SetBool("mysteryD", false);
                    animator.SetBool("mysteryA", false);
                    animator.SetBool("IsJumping", true);
                    controller.m_Rigidbody2D.velocity = Vector2.zero;
                }
                if (Input.GetKey(KeyCode.D))
                {
                    if (!rotaD)
                    {
                        GravityM = true;
                        Temple   = false;
                    }
                    animator.SetBool("mysteryD", true);
                    animator.SetBool("mysteryA", false);
                    animator.SetBool("IsJumping", false);
                    controller.m_Rigidbody2D.velocity = Vector2.zero;
                    Physics2D.gravity = new Vector2(100f, 0);
                    sr.sprite         = mysticRed;
                    rotaA             = false;
                    rotaS             = false;
                    rotaD             = true;
                }
            }
            if (invinc)
            {
                if (Input.GetKey(KeyCode.W) && !ibilityreset && !ibility)
                {
                    ibilityTimer = Time.time + 10.6f;
                    ibility      = true;

                    mT.pPause();
                    yeetinvinc.Play();
                }
                if (ibility)
                {
                    ibilityCompare = Time.time;
                    if (ibilityCompare >= ibilityTimer)
                    {
                        ibilityreset = true;
                        ibility      = false;
                        ibilityTimer = Time.time + 10;

                        mT.uUnPause();
                    }
                }
                if (ibilityreset)
                {
                    ibilityCompare = Time.time;
                    if (ibilityCompare >= ibilityTimer)
                    {
                        ibilityreset = false;
                    }
                }
            }
        }
    }
Exemple #22
0
 public override Vector3 GetPointVelocity(Vector3 point)
 {
     return(rigidbody.GetPointVelocity(point));
 }
Exemple #23
0
    void FixedUpdate()
    {
        //
        currPos = transform.position;
        currVel = rb.GetPointVelocity(currPos);
        horVec  = Input.GetAxis("Horizontal");
        verVec  = Input.GetAxis("Vertical");

        Vector2 dir = new Vector2(horVec, verVec);

        //Pushes object in desired direction if not holding shift
        if (!Input.GetKey(KeyCode.Space))
        {
            rb.AddForce(dir * swimSpeed);
        }
        else
        {
            rb.AddForce(dir * -1 * airSpeed);

            //use more air
            if (pm.pose != 'E')
            {
                pm.currAir -= Time.deltaTime * pm.drownSpeed;
            }
            else
            {
                pm.currAir -= Time.deltaTime * pm.drownSpeedE;
            }

            //
            if (dir != Vector2.zero && bTim <= 0.0f)
            {
                Instantiate(bubbls, gameObject.transform);
                bTim = Random.Range(0.05f, 0.15f);
            }
        }

        bTim -= Time.deltaTime;

        /*if(dir != Vector2.zero)
         * {
         *  //movement anim trigger
         * }
         * else
         *  //idle animation trigger
         */

        //stops object if moving -- adds drag
        if (currVel != Vector2.zero)
        {
            rb.AddForce(currVel * friction);
        }

        //invinsibility
        if (pm.invinsible)
        {
            anim.SetBool("isInvinsible", true);
        }
        else
        {
            anim.SetBool("isInvinsible", false);
        }

        //death
        if (pm.isDead)
        {
            DeathState();
        }
    }
Exemple #24
0
    void FixedUpdate()
    {
        if (Input.GetKeyDown(equipWeapButton))
        {
            keyDown = true;
        }
        else if (Input.GetKeyUp(equipWeapButton))
        {
            keyDown = false;
        }
        float currRotation = playerRB.rotation;

        rotationDiff = currRotation - prevPrevRotation;
        int tempIndex          = -1;
        int closestWeaponIndex = -1;

        if (hasWeapon)
        {
            // if you already have a weapon, throw it away
            if (Input.GetKeyUp(equipWeapButton))
            {
                if (justPickedUpWeapon)
                {
                    // don't want to throw away weapon first time we pick it up.
                    justPickedUpWeapon = false;
                }
                else
                {
                    hasWeapon = false;
                    foreach (Transform child in this.transform)
                    {
                        if (child.CompareTag("Weapon"))
                        {
                            // throw weapon away
                            child.SetParent(listOfWeapons.transform);
                            Rigidbody2D childRB = child.gameObject.AddComponent <Rigidbody2D>();
                            childRB.gravityScale = 0;
                            childRB.drag         = 0.75f;
                            childRB.angularDrag  = 1;
                            Vector2 throwVelocity = playerRB.GetPointVelocity(child.position) * 1.6f;
                            // also need to take into account player rotation velocity
                            float velX = 0;
                            float velY = 0;
                            if (rotationDiff > 0)
                            {
                                // counterclockwise fling
                                velX = Mathf.Cos((prevRotation + 90) * DEG_TO_RAD) * rotationDiff * 0.55f;
                                velY = Mathf.Sin((prevRotation + 90) * DEG_TO_RAD) * rotationDiff * 0.55f;
                            }
                            else
                            {
                                // clockwise fling
                                velX = Mathf.Cos((prevRotation - 90) * DEG_TO_RAD) * -rotationDiff * 0.55f;
                                velY = Mathf.Sin((prevRotation - 90) * DEG_TO_RAD) * -rotationDiff * 0.55f;
                            }
                            throwVelocity.x += velX;
                            throwVelocity.y += velY;

                            child.gameObject.GetComponent <Rigidbody2D>().velocity = throwVelocity;
                            child.gameObject.GetComponent <Rigidbody2D>().AddTorque(rotationDiff * 3);
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            // No weapon in hand. Look at all weapons, calculate distance to each, and determine
            // if they can be picked up
            foreach (Transform child in listOfWeapons.transform)
            {
                tempIndex++;
                // minor preliminary optimizations
                float xDistDiff = Mathf.Abs(this.transform.position.x - child.position.x);
                if (xDistDiff > weaponGrabDist)
                {
                    continue;
                }
                float yDistDiff = Mathf.Abs(this.transform.position.y - child.position.y);
                if (yDistDiff > weaponGrabDist)
                {
                    continue;
                }

                float distToWeapon = Vector2.Distance(this.transform.position, child.position);
                // if there are multiple weapons nearby, always grab the closest weapon
                if (distToWeapon < closestWeaponDist)
                {
                    // found weapon that's close enough, is potential thing to pick up
                    closestWeaponIndex = tempIndex;
                    closestWeaponDist  = distToWeapon;
                }
                closestWeaponDist = weaponGrabDist;
            }

            if (closestWeaponIndex > -1)
            {
                // Got weapon, ready to make grab indicator show up
                Transform weaponTransform = listOfWeapons.transform.GetChild(closestWeaponIndex);
                // have weapon indicator show up and set it to active
                indicatorPos.x = weaponTransform.position.x;
                indicatorPos.y = weaponTransform.position.y;
                pickUpIndicator.transform.position = indicatorPos;
                pickUpIndicator.SetActive(true);
                // picking up weapon
                if (keyDown)
                {
                    justPickedUpWeapon = true;
                    hasWeapon          = true;
                    // grab weapon, put it in front of player
                    Destroy(weaponTransform.GetComponent <Rigidbody2D>());
                    weaponTransform.SetParent(this.transform);
                    Rigidbody2D parentRB = this.GetComponent <Rigidbody2D>();
                    Debug.Log(Mathf.Sin(parentRB.rotation / Mathf.Rad2Deg));
                    // Due to physics engine behavior, grabbing a weapon while at high speeds will result in weapon not
                    // going to right position in front of player. This should offset some of the stuff
                    float equipOffsetX = Mathf.Cos(parentRB.rotation / Mathf.Rad2Deg) * parentRB.velocity.x * Time.deltaTime;
                    float equipOffsetY = -Mathf.Sin(parentRB.rotation / Mathf.Rad2Deg) * parentRB.velocity.y * Time.deltaTime;

                    weaponTransform.localPosition    = new Vector3(weaponOffsetDist + equipOffsetX, equipOffsetY, 0);
                    weaponTransform.localEulerAngles = new Vector3(0, 0, -90f);
                    if (pickUpIndicator.activeSelf)
                    {
                        pickUpIndicator.SetActive(false);
                    }
                }
            }
            else
            {
                // no weapon nearby, indicator is hidden
                if (pickUpIndicator.activeSelf)
                {
                    pickUpIndicator.SetActive(false);
                }
            }
        }
        prevPrevRotation = prevRotation;
        prevRotation     = currRotation;
    }