Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        protected override void Update(float deltaTime)
        {
            if (!GlobalNetwork.IsConnected || (CreatableInfo != null && CreatableInfo.IsAppOwner))
            {
                if (lastHolderCooldown > 0)
                {
                    lastHolderCooldown -= deltaTime;
                }

                if (Holder != null)
                {
                    Transform.Position = Holder.Transform.Position;
                }

                if (Transform.Position.Y < -200)
                {
                    Drop();
                    resetPosition = true;
                }

                if (resetPosition)
                {
                    Transform.Position = startPosition;
                    resetPosition      = false;
                }
            }
            else if (GlobalNetwork.IsClient && GlobalNetwork.IsConnected && CreatableInfo != null)
            {
                positionAnim.Step(DashCMD.GetCVar <float>("cl_interp_rep") * deltaTime);
                Transform.Position = positionAnim.Value;
            }

            base.Update(deltaTime);
        }
Ejemplo n.º 3
0
        protected override void Update(float deltaTime)
        {
            if (GlobalNetwork.IsClient && GlobalNetwork.IsConnected && CreatableInfo != null)
            {
                positionAnim.Step(DashCMD.GetCVar <float>("cl_interp_rep") * deltaTime);
                Transform.Position = positionAnim.Value;
            }
            else if (!GlobalNetwork.IsConnected || GlobalNetwork.IsServer)
            {
                if (Transform.Position.Y < -200)
                {
                    Transform.Position = startPosition;
                }
            }

            base.Update(deltaTime);
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
        protected override void Update(float deltaTime)
        {
            if (StateInfo != null)
            {
                // Update viewbob
                Viewbob.UpdateReplicated(deltaTime);

                // Step each value animation
                float interpStep = DashCMD.GetCVar <float>("cl_interp_rep") * deltaTime;
                interpPos.Step(interpStep);
                yawAnim.Step(interpStep);
                pitchAnim.Step(interpStep);

                // Update each property affected by interpolation
                Transform.Position = interpPos.Value;

                camera.Yaw   = yawAnim.Value;
                camera.Pitch = pitchAnim.Value;

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

                // Update flashlight
                flashlight.Position  = camera.Position;
                flashlight.Direction = -camera.LookVector;

                // Update the item manager
                ItemManager.UpdateReplicated(deltaTime);

                // Handle jump
                if (jumpAudioSource != null)
                {
                    jumpAudioSource.Position = Transform.Position;
                }

                if (jump)
                {
                    jump = false;
                    jumpAudioSource?.Play();
                }

                // Handle landing
                if (landAudioSource != null)
                {
                    landAudioSource.Position = Transform.Position;
                }

                if (land)
                {
                    land = false;
                    landAudioSource?.Play();
                }

                // Handle walking/running
                walkingAudioSource.IsPlaying       = isGrounded && isMoving && !IsSprinting;
                walkingAudioSource.IterationLength = (1f / GetFootstepIterationSpeed()) * 2f;
                walkingAudioSource.Update(deltaTime, Transform.Position);

                runningAudioSource.IsPlaying       = isGrounded && isMoving && IsSprinting;
                runningAudioSource.IterationLength = (1f / GetFootstepIterationSpeed()) * 2f;
                runningAudioSource.Update(deltaTime, Transform.Position);

                // Handle reload
                if (reload)
                {
                    reload = false;

                    if (ItemManager.SelectedItem is Gun gun)
                    {
                        gun.OnReplicatedReload();
                    }
                }
            }

            base.Update(deltaTime);
        }
Ejemplo n.º 8
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;
        }