示例#1
0
文件: Jump.cs 项目: Ianh4526/IASonic
        public override void OnActiveEnter(State previousState)
        {
            //Debug.Log("Jump");
            Used = true;

            Controller.Detach();
            Controller.Velocity += DMath.AngleToVector((Controller.SurfaceAngle + 90.0f) * Mathf.Deg2Rad) * ActivateSpeed;

            var roll = Manager.Get <Roll>();

            if (roll == null)
            {
                return;
            }

            if (roll.Active)
            {
                // Disable air control if jumping while rolling
                Manager.End <AirControl>();
            }
            else
            {
                Manager.Perform <Roll>(true, true);
            }
        }
示例#2
0
 /// <summary>
 /// Shifts the camera forward or backward, like in Sonic CD.
 /// </summary>
 /// <param name="forward">Whether to shift the camera forward or backward.</param>
 public void DoForwardShift(bool forward)
 {
     _forwardShifting = true;
     Camera.PanAtSpeed(
         DMath.AngleToVector(Player.RelativeAngle(forward ? 0 : 180) * Mathf.Deg2Rad) * ForwardShiftPanAmount,
         ForwardShiftPanSpeed);
 }
示例#3
0
        public override void OnPlatformEnter(TerrainCastHit hit)
        {
            var hitSide = TerrainUtility.NormalToControllerSide(hit.NormalAngle * Mathf.Rad2Deg - transform.eulerAngles.z);

            if ((BouncySides & hitSide) == 0)
            {
                return;
            }

            if (LockControl)
            {
                hit.Controller.GetComponent <MoveManager>().Get <GroundControl>().Lock(LockDuration);
            }
            if (!KeepOnGround)
            {
                hit.Controller.Detach();

                var moveManager = hit.Controller.GetComponent <MoveManager>();
                if (moveManager != null)
                {
                    moveManager.End <Roll>();
                    moveManager.Perform <AirControl>(true);
                }

                hit.Controller.IgnoreThisCollision();
            }

            if (AccurateBounce)
            {
                hit.Controller.Velocity = new Vector2(hit.Controller.Velocity.x * Mathf.Abs(Mathf.Sin(hit.NormalAngle)),
                                                      hit.Controller.Velocity.y * Mathf.Abs(Mathf.Cos(hit.NormalAngle)));
                hit.Controller.Velocity += DMath.AngleToVector(hit.NormalAngle) * Power;
            }
            else
            {
                hit.Controller.Velocity = DMath.AngleToVector(hit.NormalAngle) * Power;
            }

            if (hit.Controller.Animator != null)
            {
                var logWarnings = hit.Controller.Animator.logWarnings;
                hit.Controller.Animator.logWarnings = false;

                if (!string.IsNullOrEmpty(HitTrigger))
                {
                    hit.Controller.Animator.SetTrigger(HitTrigger);
                }

                hit.Controller.Animator.logWarnings = logWarnings;
            }

            TriggerObject(hit.Controller);
        }
示例#4
0
        /// <summary>
        /// Positions children according to the given scroll position.
        /// </summary>
        /// <param name="scrollPosition"></param>
        public void PositionChildren(float scrollPosition)
        {
            var directionRadians = Direction * Mathf.Deg2Rad;

            for (var i = 0; i < Items.Count; ++i)
            {
                var child = Items[i];
                child.transform.position = transform.position -
                                           (Vector3)(DMath.AngleToVector(directionRadians) * (i - scrollPosition) * Spacing *
                                                     Canvas.transform.localScale.x);
            }
        }
示例#5
0
        public void OnSceneGUI()
        {
            Handles.color = Color.gray;
            Handles.DrawLine(_instance.Pivot,
                             _instance.Pivot + DMath.AngleToVector(_instance.MidAngle * Mathf.Deg2Rad) * _instance.Radius);

            Handles.color = Color.white;
            Handles.DrawWireArc(_instance.Pivot,
                                _instance.transform.forward,
                                DMath.AngleToVector((_instance.MidAngle - _instance.Range / 2.0f) * Mathf.Deg2Rad),
                                _instance.Range,
                                _instance.Radius);
        }
示例#6
0
        // Translate the controller by the amount defined in Velocity and the direction defined by its
        // surface angle.
        public override void OnSurfaceStay(TerrainCastHit hit)
        {
            var controller = hit.Controller;

            if (hit.Controller == null)
            {
                return;
            }

            controller.transform.Translate(DMath.AngleToVector(controller.SurfaceAngle * Mathf.Deg2Rad) * Velocity *
                                           Time.fixedDeltaTime);

            _lastSurfaceAngle = controller.SurfaceAngle;
        }
示例#7
0
        public void Spill(int amount)
        {
            if (SpilledRingBase == null)
            {
                Debug.LogError("Can't spill rings because there's no SpilledRingBase to make copies of!");
                return;
            }

            // So that the controller doesn't instantly pick them back up
            DisableCollection();

            // Calculate the rings to spill and the amount to deduct from the total
            var toSpill = Mathf.Min(Mathf.Min(amount, Rings), MaxSpilledRings);

            Rings = Mathf.Max(Rings - amount, 0);

            // Ring spilling algorithm from https://info.sonicretro.org/SPG:Ring_Loss
            var angle      = 101.25f;
            var angleDelta = 360.0f / RingsPerCircle;
            var flip       = false;
            var circle     = 0;
            var speed      = 2.0f;

            for (var i = 0; i < toSpill; ++i)
            {
                if (i % RingsPerCircle == 0)
                {
                    angle  = 101.25f;
                    circle = i / RingsPerCircle;
                    speed  = CircleSpeeds[circle];
                }

                var ring = Instantiate(SpilledRingBase);
                ring.transform.position = transform.position;
                ring.Velocity           = DMath.AngleToVector(angle * Mathf.Deg2Rad) * speed;

                if (flip)
                {
                    ring.Velocity = new Vector2(-ring.Velocity.x, ring.Velocity.y);
                    angle        += angleDelta;
                }

                flip = !flip;
            }
        }
示例#8
0
        // Transfer momentum to the controller when it leaves the conveyor belt.
        public override void OnSurfaceExit(TerrainCastHit hit)
        {
            var controller = hit.Controller;

            if (hit.Controller == null)
            {
                return;
            }

            if (controller.Grounded)
            {
                controller.GroundVelocity += Velocity;
            }
            else
            {
                controller.Velocity += DMath.AngleToVector(_lastSurfaceAngle * Mathf.Deg2Rad) * Velocity;
            }
        }
示例#9
0
        // Q: Why is there so much code just to find the water line?
        // A: It is designed to work with surfaces of water in any orientation, in any direction of gravity.
        // Try it out with slanted water, for example!

        public RaycastHit2D FindWaterEntry()
        {
            var hit = Physics2D.Linecast((Vector2)Player.transform.position - Player.Velocity,
                                         Player.transform.position,
                                         WaterLayer);

            if (!hit || hit.fraction == 0f)
            {
                hit = Physics2D.Linecast((Vector2)Player.transform.position -
                                         DMath.AngleToVector(Player.GravityDirection * Mathf.Rad2Deg),
                                         Player.transform.position, WaterLayer);
            }

            if (hit.fraction == 0f)
            {
                return(default(RaycastHit2D));
            }

            return(hit);
        }
示例#10
0
 public void OnPerformMove(Move move)
 {
     if (move is FlameSpecial && !EnableForwardShift)
     {
         DoSpindashLag();
     }
     else if (move is LookUp)
     {
         _looking = true;
         Camera.PanAtSpeed(DMath.AngleToVector(Player.RelativeAngle(90f) * Mathf.Deg2Rad) * LookUpPanAmount,
                           LookUpPanSpeed,
                           LookUpLag);
     }
     else if (move is Duck)
     {
         _looking = true;
         Camera.PanAtSpeed(DMath.AngleToVector(Player.RelativeAngle(-90f) * Mathf.Deg2Rad) * LookDownPanAmount,
                           LookDownPanSpeed, LookDownLag);
     }
     else if (move is Spindash)
     {
         if (!EnableForwardShift)
         {
             Camera.Pan(Vector2.zero, Camera.PanTime);
         }
         else
         {
             DoForwardShift(Player.FacingForward);
         }
     }
     else if (move is Roll)
     {
         var dy = Vector2.up * -((Roll)move).HeightChange * 0.5f;
         Camera.ExtraOffset   = dy;
         Camera.BasePosition -= dy;
     }
 }
示例#11
0
        public override void OnPlatformEnter(TerrainCastHit hit)
        {
            hit.Controller.Detach();

            if (LockControl)
            {
                hit.Controller.GetComponent <MoveManager>().Get <GroundControl>().Lock();
            }

            var normal = hit.NormalAngle;

            if (AccurateBounce)
            {
                hit.Controller.Velocity = new Vector2(hit.Controller.Velocity.x * Mathf.Abs(Mathf.Sin(normal)),
                                                      hit.Controller.Velocity.y * Mathf.Abs(Mathf.Cos(normal)));
                hit.Controller.Velocity += DMath.AngleToVector(normal) * Velocity;
            }
            else
            {
                hit.Controller.Velocity = DMath.AngleToVector(normal) * Velocity;
            }

            TriggerObject();
        }
示例#12
0
        public override void To(float t)
        {
            var angle = Mathf.Lerp(MidAngle - Range / 2.0f, MidAngle + Range / 2.0f, t) * Mathf.Deg2Rad;

            transform.position = Pivot + DMath.AngleToVector(angle) * Radius;
        }