Example #1
0
        void Update()
        {
            var moveDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;

            ComponentUtils.MoveRigidbody(Rigidbody, moveDirection * Speed);
            ComponentUtils.LimitRigidbodySpeed(Rigidbody, Speed);

            if (Input.GetButtonDown(FireButtonName))
            {
                Rigidbody.AddTorque(TorquePower, ForceMode2D.Impulse);
            }
            if (Input.GetButtonDown(BreakButtonName))
            {
                Rigidbody.angularDrag = BreakAngularDrag;
            }
            if (Input.GetButtonDown(SelfDestructButtonName))
            {
                Destroy(gameObject);
            }
            if (Input.GetButtonUp(BreakButtonName))
            {
                Rigidbody.angularDrag = _defaultAngularDrag;
            }
            // Stop small rotation
            if ((Rigidbody.angularVelocity > -MinAngularVelocity) && (Rigidbody.angularVelocity < MinAngularVelocity))
            {
                Rigidbody.angularVelocity = 0f;
            }
            OnPlayerMoved?.Invoke();
        }
Example #2
0
        void FixedUpdate()
        {
            if (!BaseInited)
            {
                return;
            }
            var vectorToPlayer = (_playerTrans.position - transform.position);

            if (SpinDistance > vectorToPlayer.magnitude)
            {
                Rigidbody.AddTorque(TorqueSpeed);
                Rigidbody.angularDrag = 0.05f;
            }
            else
            {
                Rigidbody.angularDrag = BreakPower;
                Rigidbody.rotation   += ComponentUtils.SmoothRotate(transform.right, vectorToPlayer, RotationSpeed);
            }
            var forcePowerDirection = (vectorToPlayer.magnitude < 2.5f) ? -vectorToPlayer.normalized : vectorToPlayer.normalized;

            ComponentUtils.MoveRigidbody(Rigidbody, forcePowerDirection * Speed);
            ComponentUtils.LimitRigidbodySpeed(Rigidbody, Speed);
        }