Esempio n. 1
0
        /// <summary>
        /// Advance the controller and return the new position
        /// </summary>
        /// <param name="tf">the current virtual position (either TF or World Units)</param>
        /// <param name="direction">the current direction</param>
        /// <param name="mode">movement mode</param>
        /// <param name="absSpeed">speed, always positive</param>
        /// <param name="clamping">clamping mode</param>
        protected override void Advance(ref float tf, ref int direction, MoveModeEnum mode, float absSpeed, CurvyClamping clamping)
        {
            _active = this;
            switch (mode)
            {
            case MoveModeEnum.AbsoluteExtrapolate:
                if (UseCache)
                {
                    Spline.MoveByFast(ref tf, ref direction, absSpeed, Clamping);
                    if (IsSwitching)
                    {
                        mSwitchEventArgs.Spline.MoveByFast(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                        onSwitchEvent(mSwitchEventArgs);
                    }
                }
                else
                {
                    Spline.MoveBy(ref tf, ref direction, absSpeed, Clamping);
                    if (IsSwitching)
                    {
                        mSwitchEventArgs.Spline.MoveBy(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                        onSwitchEvent(mSwitchEventArgs);
                    }
                }
                break;

            case MoveModeEnum.AbsolutePrecise:
                Spline.MoveByLengthFast(ref tf, ref direction, absSpeed, Clamping);
                if (IsSwitching)
                {
                    mSwitchEventArgs.Spline.MoveByLengthFast(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                    onSwitchEvent(mSwitchEventArgs);
                }
                break;

            default:     // Relative
                if (UseCache)
                {
                    Spline.MoveFast(ref tf, ref direction, absSpeed, Clamping);
                    if (IsSwitching)
                    {
                        mSwitchEventArgs.Spline.MoveFast(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                        onSwitchEvent(mSwitchEventArgs);
                    }
                }
                else
                {
                    Spline.Move(ref tf, ref direction, absSpeed, Clamping);
                    if (IsSwitching)
                    {
                        mSwitchEventArgs.Spline.Move(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                        onSwitchEvent(mSwitchEventArgs);
                    }
                }
                break;
            }
            _active = null;
        }
        // Code that runs on entering the state.
        public override void OnEnter()
        {
            go = Fsm.GetOwnerDefaultTarget(GameObject);
            if (go)
            {
                mCurvyController = go.GetComponent <CurvyController> ();
            }

            if (!everyFrame)
            {
                DoAction();
            }

            if (!everyFrame)
            {
                Finish();
            }
        }
 protected override void Advance(ref float tf, ref int direction, CurvyController.MoveModeEnum mode, float absSpeed, CurvyClamping clamping)
 {
     base.Advance(ref tf, ref direction, mode, absSpeed, clamping);
     // Get directional vector    
     var tan = GetTangent(tf);
     float acc;
     // accelerate when going down, deccelerate when going up
     if (tan.y < 0)
         acc = Down * tan.y * Fric;
     else
         acc = Up * -tan.y * Fric;
     
     // alter speed
     Speed = Mathf.Clamp(Speed + Mass * acc * DeltaTime,MinSpeed,MaxSpeed);
     // stop at spline's end
     if (tf == 1)
         Speed = 0;
 }
Esempio n. 4
0
        /// <summary>
        /// Advance the controller and return the new position
        /// </summary>
        /// <param name="tf">the current virtual position (either TF or World Units)</param>
        /// <param name="direction">the current direction</param>
        /// <param name="mode">movement mode</param>
        /// <param name="absSpeed">speed, always positive</param>
        /// <param name="clamping">clamping mode</param>
        protected override void Advance(ref float tf, ref int direction, MoveModeEnum mode, float absSpeed, CurvyClamping clamping)
        {
            _active = this;
            switch (mode)
            {
                case MoveModeEnum.AbsoluteExtrapolate:
                    if (UseCache)
                    {
                        Spline.MoveByFast(ref tf, ref direction, absSpeed, Clamping);
                        if (IsSwitching)
                        {
                            mSwitchEventArgs.Spline.MoveByFast(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                            onSwitchEvent(mSwitchEventArgs);
                        }
                    }
                    else
                    {
                        Spline.MoveBy(ref tf, ref direction, absSpeed, Clamping);
                        if (IsSwitching)
                        {
                            mSwitchEventArgs.Spline.MoveBy(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                            onSwitchEvent(mSwitchEventArgs);
                        }
                    }
                    break;
                case MoveModeEnum.AbsolutePrecise:
                    Spline.MoveByLengthFast(ref tf, ref direction, absSpeed, Clamping);
                    if (IsSwitching)
                    {
                        mSwitchEventArgs.Spline.MoveByLengthFast(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                        onSwitchEvent(mSwitchEventArgs);
                    }
                    break;
                default: // Relative
                    if (UseCache)
                    {
                        Spline.MoveFast(ref tf, ref direction, absSpeed, Clamping);
                        if (IsSwitching)
                        {
                            mSwitchEventArgs.Spline.MoveFast(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                            onSwitchEvent(mSwitchEventArgs);
                        }
                    }
                    else
                    {
                        Spline.Move(ref tf, ref direction, absSpeed, Clamping);
                        if (IsSwitching)
                        {
                            mSwitchEventArgs.Spline.Move(ref mSwitchEventArgs.TF, ref mSwitchEventArgs.Direction, absSpeed, Clamping);
                            onSwitchEvent(mSwitchEventArgs);
                        }
                    }
                    break;
            }
            _active = null;

        }