Exemple #1
0
        public void UpdateSpeed(MapUnitFsmMoveComponent self, long nowTime)
        {
            if (nowTime > self.SpeedRandomTimeAfter)
            {
                self.SpeedTarget          = (float)RandomHelper.RandomDouble() * (self.SpeedMax - self.SpeedMin) + self.SpeedMin;
                self.SpeedRandomTimeAfter = nowTime + RandomHelper.RandomNumber(MapUnitFsmMoveComponent.SpeedRandomTimeIntervalMin, MapUnitFsmMoveComponent.SpeedRandomTimeIntervalMax);
            }

            if (nowTime > self.SpeedLerpTimeAfter)
            {
                if (self.SpeedLerpTimePrevious <= 0)
                {
                    self.SpeedLerpTimePrevious = nowTime;
                }

                long detlaTime = nowTime - self.SpeedLerpTimePrevious;
                if (Math.Abs(self.SpeedTarget - self.SpeedNow) > 0.01f)
                {
                    if (self.SpeedTarget > self.SpeedNow)
                    {
                        self.SpeedNow += 2f * (detlaTime * 0.001f);
                        if (self.SpeedTarget < self.SpeedNow)
                        {
                            self.SpeedNow = self.SpeedTarget;
                        }
                    }
                    else
                    {
                        self.SpeedNow -= 2f * (detlaTime * 0.001f);
                        if (self.SpeedTarget > self.SpeedNow)
                        {
                            self.SpeedNow = self.SpeedTarget;
                        }
                    }
                }
                self.SpeedLerpTimePrevious = nowTime;
                self.SpeedLerpTimeAfter    = nowTime + MapUnitFsmMoveComponent.SpeedLerpTimeInterval;
            }
        }