Example #1
0
        protected virtual void OnDrawGizmos()
        {
            if (_damageAreaCollider == null)
            {
                return;
            }
            if (Owner == null)
            {
                return;
            }

            float flipped = Owner.IsFacingRight ? 1f : -1f;

            _gizmoOffset    = AreaOffset;
            _gizmoOffset.x *= flipped;

            Gizmos.color = Color.white;
            if (DamageAreaShape == MeleeDamageAreaShapes.Circle)
            {
                Gizmos.DrawWireSphere(this.transform.position + _gizmoOffset, AreaSize.x / 2);
            }
            if (DamageAreaShape == MeleeDamageAreaShapes.Rectangle)
            {
                InfDebug.DrawGizmoRectangle(this.transform.position + _gizmoOffset, AreaSize, Color.red);
            }
        }
Example #2
0
        /// <summary>
        /// Checks for holes
        /// </summary>
        protected virtual void CheckForHoles()
        {
            // if we're not grounded or if we're not supposed to check for holes, we do nothing and exit
            if (!AvoidFalling || !_controller.State.IsGrounded)
            {
                return;
            }

            // we send a raycast at the extremity of the character in the direction it's facing, and modified by the offset you can set in the inspector.
            Vector2      raycastOrigin = new Vector2(transform.position.x + _direction.x * (HoleDetectionOffset.x + Mathf.Abs(GetComponent <BoxCollider2D>().bounds.size.x) / 2), transform.position.y + HoleDetectionOffset.y - (transform.localScale.y / 2));
            RaycastHit2D raycast       = InfDebug.RayCast(raycastOrigin, -transform.up, HoleDetectionRaycastLength, _controller.PlatformMask | _controller.MovingPlatformMask | _controller.OneWayPlatformMask | _controller.MovingOneWayPlatformMask, Color.gray, true);

            // if the raycast doesn't hit anything
            if (!raycast)
            {
                // we change direction
                ChangeDirection();
            }
        }
Example #3
0
        /// <summary>
        /// Determines the weapon rotation based on the current aim direction
        /// </summary>
        protected virtual void DetermineWeaponRotation()
        {
            if (_currentAim != Vector3.zero)
            {
                if (_direction != Vector3.zero)
                {
                    CurrentAngle = Mathf.Atan2(_currentAim.y, _currentAim.x) * Mathf.Rad2Deg;
                    if (RotationMode == RotationModes.Strict4Directions || RotationMode == RotationModes.Strict8Directions)
                    {
                        CurrentAngle = InfMaths.RoundToClosest(CurrentAngle, _possibleAngleValues);
                    }

                    // we add our additional angle
                    CurrentAngle += _additionalAngle;

                    // we clamp the angle to the min/max values set in the inspector
                    if (_weapon.Owner.IsFacingRight)
                    {
                        CurrentAngle = Mathf.Clamp(CurrentAngle, MinimumAngle, MaximumAngle);
                    }
                    else
                    {
                        CurrentAngle = Mathf.Clamp(CurrentAngle, -MaximumAngle, -MinimumAngle);
                    }
                    _lookRotation = Quaternion.Euler(CurrentAngle * Vector3.forward);
                    RotateWeapon(_lookRotation);
                }
            }
            else
            {
                /*CurrentAngle = 0f;
                 * if (_characterGravity == null)
                 * {
                 *      RotateWeapon(_initialRotation);
                 * }
                 * else
                 * {
                 *      RotateWeapon (_characterGravity.transform.rotation);
                 * }*/
            }
            InfDebug.DebugDrawArrow(this.transform.position, _currentAim.normalized, Color.green);
        }