예제 #1
0
        void Update()
        {
            if (!GameController.IsPaused())
            {
                targetX = Input.GetAxis("Mouse X");
                targetY = Input.GetAxis("Mouse Y");

                int y = Mathf.RoundToInt(ServerController.player.mouseLook.mouseLookRoot.localEulerAngles.x);
                if (y == 270 || y == 90)
                {
                    targetY = 0f;
                }
            }
            else
            {
                targetX = 0f;
                targetY = 0f;
            }

            Vector3 targetVector = new Vector3(targetY, -targetX) * template.strengh * Settings.Sensitivity;

            targetVector = Vector3.ClampMagnitude(targetVector, template.maxDistance);

            transform.localRotation = Quaternion.Slerp(
                transform.localRotation, Quaternion.Euler(targetVector),
                template.lerpSpeed > 0f ? template.lerpSpeed * Time.deltaTime : 1f
                );
        }
예제 #2
0
        public bool Moving()
        {
            if (photonView.isMine)
            {
                return(!GameController.IsPaused() && (
                           Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) ||
                           Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.A)
                           ));
            }

            return(player.walking);
        }
예제 #3
0
파일: Knife.cs 프로젝트: Alan-Baylis/VOX
        void Update()
        {
            transform.localPosition = Settings.GlobalViewmodelOffset;

            if (!GameController.IsPaused())
            {
                if (Input.GetKey(KeyCode.Mouse0) && canAttack)
                {
                    Attack();
                }
            }
        }
예제 #4
0
파일: Gun.cs 프로젝트: Alan-Baylis/VOX
        void Update()
        {
            if (!GameController.IsPaused())
            {
                tryingToAim = Input.GetKey(KeyCode.Mouse1) && canAim;
                bool tryingToShoot = info.auto ? Input.GetKey(KeyCode.Mouse0) : Input.GetKeyDown(KeyCode.Mouse0);

                if (tryingToShoot && canShoot)
                {
                    Fire();
                }

                if (Input.GetKeyDown(KeyCode.R) && canReload)
                {
                    Reload();
                }
            }
            else
            {
                tryingToAim = false;
            }

            if (player.running && !drawing)
            {
                //Running
                Vector3  position   = info.runningLoc.position + Settings.GlobalViewmodelOffset;
                Location runningLoc = new Location(position, info.runningLoc.eulerAngles, info.runningLoc.scale);

                targetLoc = runningLoc;
            }
            else
            {
                //Walking or Aiming
                Vector3  position  = info.normalLoc.position + Settings.GlobalViewmodelOffset;
                Location normalLoc = new Location(position, info.normalLoc.eulerAngles, info.normalLoc.scale);

                targetLoc = !aiming ? normalLoc : info.aimingLoc;
            }

            transform.localPosition = Vector3.Lerp(transform.localPosition, targetLoc.position, (aiming ? aimingLerpSpeed : lerpSpeed) * Time.deltaTime);
            transform.localRotation = Quaternion.Slerp(transform.localRotation, targetLoc.rotation, (aiming ? aimingLerpSpeed : lerpSpeed) * Time.deltaTime);
            transform.localScale    = Vector3.Lerp(transform.localScale, targetLoc.scale, (aiming ? aimingLerpSpeed : lerpSpeed) * Time.deltaTime);

            main.camFov.fov = player.aiming ? fov - info.aimedFov : fov;
        }
예제 #5
0
        void Update()
        {
            if (photonView.isMine)
            {
                recoill = Mathf.Lerp(recoill, 0f, recoillLerpSpeed * Time.deltaTime);

                if (!GameController.IsPaused())
                {
                    float yRot = Input.GetAxis("Mouse X") * Settings.Sensitivity;
                    _xRot -= Input.GetAxis("Mouse Y") * Settings.Sensitivity;
                    _xRot  = Mathf.Clamp(_xRot, -90f, 90f);

                    transform.Rotate(0f, yRot, 0f);
                }

                mouseLookRoot.localEulerAngles = new Vector3(Mathf.Clamp(_xRot - recoill, -999f, 999f), 0f, 0f);
            }
        }
예제 #6
0
파일: Player.cs 프로젝트: Alan-Baylis/VOX
        void Update()
        {
            if (photonView.isMine)
            {
                SetCursorLocked(!GameController.IsPaused());

                worldModel.currentIndex = items.currentIndex;
                worldModel.Refresh(mouseLook.xRot);
            }
            else
            {
                float sendRate = 1f / (float)PhotonNetwork.sendRateOnSerialize;
                float ratio    = Mathf.InverseLerp(t, t + sendRate, Time.time);

                transform.position = Vector3.Lerp(startPos, endPos, ratio);
                transform.rotation = Quaternion.Slerp(startRot, endRot, ratio);
                worldModel.Refresh(Mathf.Lerp(startXRot, endXRot, ratio));
            }
        }
예제 #7
0
파일: Grenade.cs 프로젝트: Alan-Baylis/VOX
        void Update()
        {
            transform.localPosition = Settings.GlobalViewmodelOffset;

            if (!GameController.IsPaused())
            {
                if (Input.GetKey(KeyCode.Mouse0) && canAttack)
                {
                    StartThrowing();
                }
                if (Input.GetKeyUp(KeyCode.Mouse0) && canAttack)
                {
                    FinishThrowing();
                }
            }
            else
            {
                t = Time.time + 0.1f;
            }
        }
예제 #8
0
        void Update()
        {
            if (photonView.isMine)
            {
                headbob.animate = Moving();

                bool      crouching = Crouching();
                Transform cam       = player.mouseLook.mouseLookRoot;
                cam.localPosition = Vector3.Lerp(cam.localPosition, Vector3.up * (crouching ? crouchingCameraHeight : normalCameraHeight), crouchCamLerpSpeed * Time.deltaTime);

                if (crouching != lastCrouching)
                {
                    lastCrouching = crouching;

                    controller.height = crouching ? crouchingHeight : normalHeight;
                    controller.center = Vector3.up * controller.height / 2f;
                }

                if (Input.GetKeyDown(KeyCode.Space) && !GameController.IsPaused() && grounded)
                {
                    requestJump = true;
                }
            }
        }
예제 #9
0
        void Update()
        {
            if (photonView.isMine && !GameController.IsPaused())
            {
                if (primary == null && secondary == null && melee == null && item1 == null && item2 == null)
                {
                    return;
                }

                if (Input.GetKeyDown(KeyCode.Alpha1) && primary != null)
                {
                    ChangeWeapon(1);
                }
                if (Input.GetKeyDown(KeyCode.Alpha2) && secondary != null)
                {
                    ChangeWeapon(2);
                }
                if (Input.GetKeyDown(KeyCode.Alpha3) && melee != null)
                {
                    ChangeWeapon(3);
                }
                if (Input.GetKeyDown(KeyCode.Alpha4) && item1 != null)
                {
                    ChangeWeapon(4);
                }
                if (Input.GetKeyDown(KeyCode.Alpha5) && item2 != null)
                {
                    ChangeWeapon(5);
                }

                if (Input.GetKeyDown(KeyCode.Q) && lastIndex != -1)
                {
                    ChangeWeapon(lastIndex);
                }
            }
        }
예제 #10
0
        void FixedUpdate()
        {
            if (photonView.isMine)
            {
                if (!GameController.IsPaused())
                {
                    inputZ = Mathf.Lerp(inputZ, GetAxisFromKeys(KeyCode.W, KeyCode.S), inputLerpSpeed * Time.deltaTime);
                    inputX = Mathf.Lerp(inputX, GetAxisFromKeys(KeyCode.D, KeyCode.A), inputLerpSpeed * Time.deltaTime);
                }
                else
                {
                    inputZ = Mathf.Lerp(inputZ, 0f, inputLerpSpeed * Time.deltaTime);
                    inputX = Mathf.Lerp(inputX, 0f, inputLerpSpeed * Time.deltaTime);
                }

                if (grounded)
                {
                    if (fallStartLevel != float.MinValue)
                    {
                        if (transform.position.y < fallStartLevel - fallingDamageThreshold)
                        {
                            FallingDamage(fallStartLevel - transform.position.y);
                        }
                    }

                    bool crouch = Input.GetKey(KeyCode.C) && grounded;

                    if (!GameController.IsPaused() && Input.GetKey(KeyCode.LeftShift) && !crouch && !Crouching() && Moving() && !player.reloading)
                    {
                        //Running
                        speed            = runningSpeed;
                        headbob.template = runningHeadbob;
                    }
                    else
                    {
                        sway.template = !player.aiming ? walkingSway : aimingSway;

                        if (crouch && !GameController.IsPaused())
                        {
                            //Crouching or CrouchAiming
                            speed            = !player.aiming ? crouchingSpeed : crouchAimingSpeed;
                            headbob.template = !player.aiming ? crouchingHeadbob : crouchAimingHeadbob;
                        }
                        else
                        {
                            //Walking or Aiming
                            speed            = !player.aiming ? walkingSpeed : aimingSpeed;
                            headbob.template = !player.aiming ? walkingHeadbob : aimingHeadbob;
                        }
                    }

                    moveDirection = new Vector3(inputX, -antiBumpFactor, inputZ);
                    moveDirection = transform.TransformDirection(moveDirection) * speed;

                    if (requestJump)
                    {
                        requestJump     = false;
                        moveDirection.y = jumpSpeed;
                    }
                }
                else
                {
                    if (fallStartLevel == float.MinValue)
                    {
                        fallStartLevel = transform.position.y;
                    }

                    if (airControl)
                    {
                        moveDirection.x = inputX * speed;
                        moveDirection.z = inputZ * speed;
                        moveDirection   = transform.TransformDirection(moveDirection);
                    }
                }

                float y = moveDirection.y;
                moveDirection.y = 0f;
                moveDirection   = Vector3.ClampMagnitude(moveDirection, speed);
                moveDirection.y = y;

                moveDirection.y -= gravity * Time.deltaTime;

                controller.Move(moveDirection * Time.deltaTime);
            }
        }
예제 #11
0
        void Update()
        {
            if (!chatField.gameObject.activeInHierarchy)
            {
                if (!classCreation.classes.activeInHierarchy)
                {
                    if (!menu.activeInHierarchy)
                    {
                        if (Input.GetKeyDown(KeyCode.Escape))
                        {
                            menu.SetActive(true);
                        }
                        if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
                        {
                            chatField.gameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        if (Input.GetKeyDown(KeyCode.Escape))
                        {
                            UI_Resume();
                        }
                    }
                }
                else
                {
                    UI_Resume();
                }
            }
            else
            {
                if (!chatField.isFocused)
                {
                    chatField.Select();
                    chatField.ActivateInputField();
                }

                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    chatField.text = "";
                    chatField.gameObject.SetActive(false);
                }

                if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
                {
                    if (chatField.text != "")
                    {
                        SendChatMessage(chatField.text);
                    }

                    chatField.text = "";
                    chatField.gameObject.SetActive(false);
                }
            }

            scoreboard.scoreboard.SetActive((Input.GetKey(KeyCode.Tab) && !GameController.IsPaused()) || (ServerController.HasRoundEnded && !menu.activeSelf));

            float time    = (float)ServerController.RemainingTime;
            int   minutes = Mathf.FloorToInt(time / 60);
            int   seconds = Mathf.FloorToInt(time % 60);

            timerText.text = string.Format("{0}:{1:00}", minutes, seconds);

            hitCG.alpha          = Mathf.Lerp(hitCG.alpha, 0f, hitLerpSpeed * Time.deltaTime);
            crosshairImage.color = Color.Lerp(crosshairImage.color, Color.white, hitmarkerLerpSpeed * Time.deltaTime);

            Player player = ServerController.player;

            if (player != null)
            {
                GunBase currentGunBase = player.items.currentGun;
                if (currentGunBase != null)
                {
                    GunInfo currentGunInfo = currentGunBase.info;

                    bool isCrosshairHidden = player.isDead || (currentGunInfo.hideCrosshair && !player.reloading);
                    bool hidingCrosshair   = player.aiming;

                    if (currentGunBase is Grenade)
                    {
                        Grenade currentGrenade = (Grenade)currentGunBase;
                        hidingCrosshair = currentGrenade.throwing;
                    }

                    float targetCrosshairAlpha = hidingCrosshair ? (currentGunInfo.showCrosshairWhileAiming ? 1f : 0f) : (isCrosshairHidden ? 0f : 1f);

                    float multiplier = 1f;

                    if (hidingCrosshair)
                    {
                        multiplier = 0f;
                    }
                    else if (player.running)
                    {
                        multiplier = currentGunInfo.runningMultiplier;
                    }
                    else if (player.crouching)
                    {
                        multiplier = currentGunInfo.crouchingMultiplier;
                    }
                    else
                    {
                        multiplier = 1f;
                    }

                    Vector2 targetCrosshairSize = Vector2.one * (currentGunInfo.defaultCrosshairSize * multiplier);

                    crosshairCP.alpha   = Mathf.Lerp(crosshairCP.alpha, targetCrosshairAlpha, Gun.aimingLerpSpeed * Time.deltaTime);
                    crosshair.sizeDelta = Vector2.Lerp(crosshair.sizeDelta, targetCrosshairSize, crosshairSizeLerpSpeed * Time.deltaTime);

                    if (currentGunBase is Gun)
                    {
                        Gun currentGun = currentGunBase as Gun;

                        ammoText.gameObject.SetActive(true);

                        if (currentGun.maxAmmo >= 0)
                        {
                            ammoText.text = string.Format("{0}/{1}", currentGun.ammo, currentGun.maxAmmo);
                        }
                        else
                        {
                            ammoText.text = currentGun.ammo.ToString();
                        }

                        if (player.reloading)
                        {
                            float value = Mathf.InverseLerp(currentGun.reloadingT, currentGun.reloadingT + currentGunInfo.reloadTime, Time.time);
                            crosshairCP.transform.localEulerAngles = Vector3.Lerp(Vector3.zero, Vector3.forward * 90f, value);
                            crosshairCP.transform.localScale       = Vector3.one;
                        }
                    }
                    else if (currentGunBase is Grenade)
                    {
                        Grenade currentGrenade = currentGunBase as Grenade;

                        ammoText.gameObject.SetActive(true);
                        ammoText.text = currentGrenade.grenades.ToString();
                    }
                    else if (currentGunBase is Knife)
                    {
                        ammoText.gameObject.SetActive(false);
                    }

                    healthBarMask.localScale = new Vector3(Mathf.Clamp01((float)player.health / 100f), 1f, 1f);

                    if (healthBarMask.localScale.x > 0f)
                    {
                        healthBar.localScale = new Vector3(1f / healthBarMask.localScale.x, 1f, 1f);
                    }
                }
            }
        }