Пример #1
0
        protected override void Update(float deltaTime)
        {
            if (GlobalNetwork.IsClient)
            {
                Camera cam = Dash.Engine.Graphics.Camera.Active;

                if (OwnerPlayer.IsAiming)
                {
                    modelAnim.SetTarget(aimModelOffset);
                    fovAnim.SetTarget(cam.DefaultFOV * AIM_FOV_SCALE);
                    cam.FPSMouseSensitivity = cam.DefaultFPSMouseSensitivity * AIM_MOUSE_SENSITIVITY_SCALE;
                }
                else
                {
                    modelAnim.SetTarget(normalModelOffset);
                    fovAnim.SetTarget(cam.DefaultFOV);
                    cam.FPSMouseSensitivity = cam.DefaultFPSMouseSensitivity;
                }

                modelAnim.Step(deltaTime * 12);
                fovAnim.Step(deltaTime * 12);
                cam.FOV     = fovAnim.Value;
                ModelOffset = modelAnim.Value;
            }

            base.Update(deltaTime);
        }
        public override void OnClientInbound(PlayerSnapshot snapshot)
        {
            ItemManager.Equip(snapshot.SelectedItem, forceEquip: true);
            ItemManager.MuzzleFlashIterations += snapshot.TimesShot;

            yawAnim.SetTarget(snapshot.CamYaw);
            pitchAnim.SetTarget(snapshot.CamPitch);
            interpPos.SetTarget(new Vector3(snapshot.X, snapshot.Y, snapshot.Z));

            flashlight.Visible = snapshot.IsFlashlightOn;
            reload             = snapshot.IsReloading;

            CharacterController.IsCrouching = snapshot.IsCrouching;
            IsSprinting = snapshot.IsSprinting;
            isMoving    = snapshot.IsMoving;
            IsAiming    = snapshot.IsAiming;
            isGrounded  = snapshot.IsGrounded;
            jump        = snapshot.IsJumping;

            if (isGrounded && !lastGrounded)
            {
                land = true;
            }

            lastGrounded = snapshot.IsGrounded;
        }
Пример #3
0
        public void Update(float deltaTime)
        {
            Transform           playerTransform = player.Transform;
            CharacterController cc = player.CharacterController;

            float distMoved = (playerTransform.Position - lastPlayerPos).Length;
            bool  sprinting = distMoved > 0 && !Input.GetControl("Walk") &&
                              !player.IsAiming && Input.GetControl("Sprint") && !cc.IsCrouching;

            rollAnim.SetTarget(sprinting ? player.StrafeDir * 0.75f : 0);

            if (sprinting && cc.IsGrounded && cc.IsMoving)
            {
                if (offsetAnim.I == 1)
                {
                    if (bobI == 0)
                    {
                        offsetAnim.SetTarget(new Vector3(0, 0.3f, 0));
                        bobI = 1;
                    }
                    else if (bobI == 1)
                    {
                        offsetAnim.SetTarget(new Vector3(0, -0.3f, 0));
                        bobI = 0;
                    }
                }
            }
            else if (offsetAnim.Target != Vector3.Zero)
            {
                bobI = 0;
                offsetAnim.SetTarget(Vector3.Zero);
            }

            offsetAnim.Step(deltaTime * 7);
            shakeFactorAnim.Step(deltaTime * shakeFalloffRate);
            rollAnim.Step(deltaTime * 10);

            if (recoilTimes >= 0)
            {
                recoilTimes--;
            }

            lastPlayerPos = playerTransform.Position;
        }
Пример #4
0
        public void OnClientInbound(NetEntitySnapshot _snapshot)
        {
            CommandPostEntitySnapshot snapshot = (CommandPostEntitySnapshot)_snapshot;

            positionAnim.SetTarget(new Vector3(snapshot.X, snapshot.Y, snapshot.Z));

            if ((positionAnim.Target - positionAnim.Value).Length > 20)
            {
                positionAnim.SnapTo(positionAnim.Target);
            }
        }
Пример #5
0
        protected override void Update(float deltaTime)
        {
            if (GlobalNetwork.IsClient)
            {
                Camera cam = Dash.Engine.Graphics.Camera.Active;

                if (OwnerPlayer.IsAiming)
                {
                    modelAnim.SetTarget(AimModelOffset);
                    fovAnim.SetTarget(cam.DefaultFOV * GunConfig.AimFOVScale);
                    cam.FPSMouseSensitivity = cam.DefaultFPSMouseSensitivity * GunConfig.AimMouseSensitivityScale;
                }
                else
                {
                    modelAnim.SetTarget(normalModelOffset);
                    fovAnim.SetTarget(cam.DefaultFOV);
                    cam.FPSMouseSensitivity = cam.DefaultFPSMouseSensitivity;
                }

                modelAnim.Step(deltaTime * 12);
                fovAnim.Step(deltaTime * 12);
                cam.FOV     = fovAnim.Value;
                ModelOffset = modelAnim.Value;
            }

            if (IsReloading && reloadTimeLeft > 0)
            {
                reloadTimeLeft -= deltaTime;
            }
            else if (IsReloading && reloadTimeLeft <= 0)
            {
                IsReloading = false;
                RefillAmmo();
            }

            base.Update(deltaTime);
        }
Пример #6
0
        protected override void Update(float deltaTime)
        {
            if (StateInfo != null)
            {
                // Sync our server transform with the client's reported position
                Vector3 clientPosition = new Vector3(ClientSnapshot.X, ClientSnapshot.Y, ClientSnapshot.Z);
                if (movementAnim.Target != clientPosition)
                {
                    movementAnim.SetTarget(clientPosition);
                }

                movementAnim.Step(deltaTime * 30f);

                Transform.Position = movementAnim.Value;

                // Sync our server camera with the client's
                camera.Yaw   = ClientSnapshot.CamYaw;
                camera.Pitch = ClientSnapshot.CamPitch;

                Gun  gun             = ItemManager.SelectedItem as Gun;
                bool reloadingBefore = gun != null && gun.IsReloading;

                // Update item in hand
                ItemManager.Update(false, false, false, false, ClientSnapshot.Reload, deltaTime);

                if (gun != null && gun.IsReloading && !reloadingBefore)
                {
                    reloaded = true;
                }

                // Only process bullets if the player is alive
                if (Health > 0)
                {
                    while (bulletsToFire.Count > 0)
                    {
                        // Attempt to fire client bullet
                        NetworkBullet bullet = bulletsToFire.Dequeue();

                        camera.Pitch    = bullet.CameraPitch;
                        camera.Yaw      = bullet.CameraYaw;
                        camera.Position = bullet.Origin;
                        camera.Update(deltaTime);

                        LastBulletDeltaTime = (Environment.TickCount - bullet.CreatedAt) + bullet.Ticks;

                        ItemManager.TryInvokePrimaryFire();
                    }
                }

                // Handle the client dropping intel
                if (ClientSnapshot.DropIntel)
                {
                    DropIntel();
                }

                // Handle the player falling off the map
                if (Transform.Position.Y < -200)
                {
                    this.Damage(100, "The Void");
                }

                // Process refresh cooldown
                if (refreshCooldown > 0)
                {
                    refreshCooldown -= deltaTime;
                }

                // Update our "fake" camera
                camera.Position = Transform.Position + new Vector3(0, Size.Y / 2f - 1.1f, 0);
                camera.Update(deltaTime);

                // Save the current transform for future rollbacks
                StoreCurrentTransform();
            }

            base.Update(deltaTime);
        }
Пример #7
0
        public void Update(float deltaTime)
        {
            bool playerMoved   = cc.IsMoving && Maths.Distance(lastPos, player.Transform.Position) > 0;
            bool heldItemIsGun = itemManager.SelectedItem != null && (itemManager.SelectedItem.Type.HasFlag(ItemType.Gun) ||
                                                                      itemManager.SelectedItem.Type.HasFlag(ItemType.MelonLauncher));
            bool isSprinting = heldItemIsGun && player.IsSprinting && playerMoved;

            Vector3 useBobOffset = player.IsAiming ? bobOffset : isSprinting ? bobSprintOffset : Vector3.Zero;

            if (cc.IsMoving && Maths.Distance(lastPos, player.Transform.Position) > 0 && cc.IsGrounded)
            {
                if (!lastMoving || bobAnim.I == 1)
                {
                    // Switch state
                    if (bobState == BOB_ORIGIN)
                    {
                        bobState = BOB_TOP1;
                        bobAnim.SetTarget((bobTop + useBobOffset) * GetDistMod());
                    }
                    else if (bobState == BOB_TOP1)
                    {
                        bobState = BOB_LEFT;
                        bobAnim.SetTarget((bobLeft + useBobOffset) * GetDistMod());
                    }
                    else if (bobState == BOB_LEFT)
                    {
                        bobState = BOB_TOP2;
                        bobAnim.SetTarget((bobTop + useBobOffset) * GetDistMod());
                    }
                    else if (bobState == BOB_TOP2)
                    {
                        bobState = BOB_ORIGIN;
                        bobAnim.SetTarget(bobOrigin + useBobOffset * GetDistMod());
                    }
                }
            }
            else if (!cc.IsGrounded)
            {
                if (bobState != BOB_TOP1 || isSprinting != lastIsSprinting || lastIsAiming != player.IsAiming)
                {
                    bobState = BOB_TOP1;
                    Vector3 bob = player.IsAiming ? bobTopAiming : bobTop;
                    bobAnim.SetTarget((bob + useBobOffset) * GetDistMod());
                }
            }
            else
            {
                if (bobState != BOB_ORIGIN || bobAnim.Target != bobOrigin)
                {
                    // Return to origin
                    bobState = BOB_ORIGIN;
                    bobAnim.SetTarget(bobOrigin);
                }
            }

            if (player.IsStrafing)
            {
                float tilt = player.IsAiming ? 2 : 5;

                if (player.StrafeDir > 0)
                {
                    tiltAnim.SetTarget(tilt);
                }
                else
                {
                    tiltAnim.SetTarget(-tilt);
                }
            }
            else
            {
                if (tiltAnim.Target != 0)
                {
                    tiltAnim.SetTarget(0);
                }
            }

            Vector3 deltaPos = player.Transform.Position - lastPos;

            if (deltaPos.Y > 5)
            {
                deltaPos.Y = 0.75f;
            }

            float yawOffset = 0, pitchOffset = 0;

            if (isSprinting)
            {
                yawOffset   = SPRINT_TILT_YAW;
                pitchOffset = SPRINT_TILT_PITCH;
            }

            float pitchSwayDamper = player.IsAiming ? 0.2f : 1f;
            float yawSwayDamper   = player.IsAiming ? 0.7f : 1f;

            swayAnim.SetTarget(new Vector3(
                                   (lastPitch - Camera.Active.Pitch + (deltaPos.Y * 8) + pitchOffset) * pitchSwayDamper,
                                   (Camera.Active.Yaw - lastYaw + yawOffset) * yawSwayDamper,
                                   0));

            bobAnim.Step(deltaTime * GetSpeed());
            tiltAnim.Step(deltaTime * 5);
            swayAnim.Step(deltaTime * 8);
            kickbackAnim.Step(deltaTime * 8);

            lastMoving = cc.IsMoving;
            lastPos    = player.Transform.Position;

            lastYaw         = Camera.Active.Yaw;
            lastPitch       = Camera.Active.Pitch;
            lastIsSprinting = isSprinting;
            lastIsAiming    = player.IsAiming;
        }