Exemplo n.º 1
0
        /// <summary>
        /// SV_WaterMove
        /// </summary>
        static void WaterMove()
        {
            //
            // user intentions
            //
            Vector3 pangle = Common.ToVector(ref _Player.v.v_angle);

            Mathlib.AngleVectors(ref pangle, out _Forward, out _Right, out _Up);
            Vector3 wishvel = _Forward * _Cmd.forwardmove + _Right * _Cmd.sidemove;

            if (_Cmd.forwardmove == 0 && _Cmd.sidemove == 0 && _Cmd.upmove == 0)
            {
                wishvel.Z -= 60;                // drift towards bottom
            }
            else
            {
                wishvel.Z += _Cmd.upmove;
            }

            float wishspeed = wishvel.Length;

            if (wishspeed > _MaxSpeed.Value)
            {
                wishvel  *= _MaxSpeed.Value / wishspeed;
                wishspeed = _MaxSpeed.Value;
            }
            wishspeed *= 0.7f;

            //
            // water friction
            //
            float newspeed, speed = Mathlib.Length(ref _Player.v.velocity);

            if (speed != 0)
            {
                newspeed = (float)(speed - Host.FrameTime * speed * _Friction.Value);
                if (newspeed < 0)
                {
                    newspeed = 0;
                }
                Mathlib.VectorScale(ref _Player.v.velocity, newspeed / speed, out _Player.v.velocity);
            }
            else
            {
                newspeed = 0;
            }

            //
            // water acceleration
            //
            if (wishspeed == 0)
            {
                return;
            }

            float addspeed = wishspeed - newspeed;

            if (addspeed <= 0)
            {
                return;
            }

            Mathlib.Normalize(ref wishvel);
            float accelspeed = (float)(_Accelerate.Value * wishspeed * Host.FrameTime);

            if (accelspeed > addspeed)
            {
                accelspeed = addspeed;
            }

            wishvel *= accelspeed;
            _Player.v.velocity.x += wishvel.X;
            _Player.v.velocity.y += wishvel.Y;
            _Player.v.velocity.z += wishvel.Z;
        }