// Update is called once per frame private void Update() { RotateView(); // the jump state needs to read here to make sure it is not missed if ((!m_Jump) && (!m_Jumping)) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); //PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
// Update is called once per frame private void Update() { RotateView(); // the jump state needs to read here to make sure it is not missed if (!_jump) { _jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!_previouslyGrounded && _characterController.isGrounded) { StartCoroutine(_jumpBob.DoBobCycle()); PlayLandingSound(); _moveDir.y = 0f; _jumping = false; } if (!_characterController.isGrounded && !_jumping && _previouslyGrounded) { _moveDir.y = 0f; } _previouslyGrounded = _characterController.isGrounded; }
// Update is called once per frame private void Update() { // Prevent control is connected to Photon and represent the localPlayer if (!photonView.isMine && PhotonNetwork.connected) { return; } // If currently the character is not available, don't do anything if (!m_IsCharacterControllable) { return; } // Mouse lool control RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
void MovementaBehaviour() { isDown = true; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; if (Input.GetKeyDown(KeyCode.Escape)) { isDown = false; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } if (isDown) { RotateView(); } // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = Input.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
private void Update() { if (!m_Activated) { return; } RotateView(); if (!m_Jump && m_CharacterController.isGrounded) { m_Jump = Input.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; if (lastPos != transform.position) { isMoving = true; lastPos = transform.position; } else { isMoving = false; } }
// Update is called once per frame private void Update() { isCrouching = Input.GetKey(KeyCode.LeftControl); RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = Input.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; if (isCrouching) { m_CharacterController.height = Mathf.Lerp(m_CharacterController.height, crouchHeight, Time.deltaTime * 9f); } else { float lastHeight = m_CharacterController.height; m_CharacterController.height = Mathf.Lerp(m_CharacterController.height, playerHeight, Time.deltaTime * 9f); Vector3 tmpPos = transform.position; //tmpPos.y += (m_CharacterController.height - lastHeight); //transform.position = tmpPos; } }
private void Update() { Vector3 newCameraPosition; if (rigidbodyFirstPersonController.Velocity.magnitude > 0 && rigidbodyFirstPersonController.Grounded) { Camera.transform.localPosition = motionBob.DoHeadBob(rigidbodyFirstPersonController.Velocity.magnitude * (rigidbodyFirstPersonController.Running ? RunningStrideLengthen : 1f)); newCameraPosition = Camera.transform.localPosition; newCameraPosition.y = Camera.transform.localPosition.y - jumpAndLandingBob.Offset(); } else { newCameraPosition = Camera.transform.localPosition; newCameraPosition.y = m_OriginalCameraPosition.y - jumpAndLandingBob.Offset(); } Camera.transform.localPosition = newCameraPosition; if (!m_PreviouslyGrounded && rigidbodyFirstPersonController.Grounded) { StartCoroutine(jumpAndLandingBob.DoBobCycle()); } m_PreviouslyGrounded = rigidbodyFirstPersonController.Grounded; }
// Update is called once per frame protected virtual void Update() { GetAbilityInput(); RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; m_Jump = false; jumpstaken = 0; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
/// <summary> /// /// </summary> public override void OnUpdate() { Velocity = m_CharacterController.velocity; VelocityMagnitude = Velocity.magnitude; RotateView(); if (Finish) { return; } if (!bl_UtilityHelper.GetCursorState || bl_GameData.Instance.isChating) { return; } // the jump state needs to read here to make sure it is not missed #if INPUT_MANAGER if (!m_Jump && State != PlayerState.Crouching && (Time.time - lastJumpTime) > JumpMinRate) { m_Jump = bl_Input.GetKeyDown("Jump"); } if (State != PlayerState.Jumping) { if (KeepToCrouch) { Crounching = bl_Input.GetKey("Crouch"); if (Crounching != lastCrouchState) { if (Crounching) { State = PlayerState.Crouching; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = CrouchIcon; } else { State = PlayerState.Idle; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = StandIcon; } bl_UCrosshair.Instance.OnCrouch(Crounching); lastCrouchState = Crounching; } } else { if (bl_Input.GetKeyDown("Crouch")) { Crounching = !Crounching; if (Crounching) { State = PlayerState.Crouching; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = CrouchIcon; } else { State = PlayerState.Idle; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = StandIcon; } bl_UCrosshair.Instance.OnCrouch(Crounching); } } } #else if (!bl_UtilityHelper.isMobile) { if (!m_Jump && State != PlayerState.Crouching && (Time.time - lastJumpTime) > JumpMinRate) { m_Jump = Input.GetKeyDown(KeyCode.Space); } if (State != PlayerState.Jumping && State != PlayerState.Climbing) { if (KeepToCrouch) { Crounching = Input.GetKey(KeyCode.C); if (Crounching != lastCrouchState) { if (Crounching) { State = PlayerState.Crouching; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = CrouchIcon; } else { State = PlayerState.Idle; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = StandIcon; } bl_UCrosshair.Instance.OnCrouch(Crounching); lastCrouchState = Crounching; } } else { if (Input.GetKeyDown(KeyCode.C)) { Crounching = !Crounching; if (Crounching) { State = PlayerState.Crouching; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = CrouchIcon; } else { State = PlayerState.Idle; bl_UIReferences.Instance.PlayerUI.PlayerStateIcon.sprite = StandIcon; } bl_UCrosshair.Instance.OnCrouch(Crounching); } } } } #endif if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); isFalling = false; if (FallDamage && hasTouchGround) { CalculateFall(); } JumpDirection = 0; m_MoveDir.y = 0f; m_Jumping = false; State = PlayerState.Idle; bl_EventHandler.OnSmallImpactEvent(); } else if (m_PreviouslyGrounded && !m_CharacterController.isGrounded) { if (!isFalling) { PostGroundVerticalPos = m_Transform.position.y; isFalling = true; fallingTime = Time.time; } } if (isFalling) { FallingCalculation(); } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } Crouch(); m_PreviouslyGrounded = m_CharacterController.isGrounded; }
// Update is called once per frame protected virtual void Update() { //CHANGE CLASS if (Input.GetKeyDown(KeyCode.F1)) { if (!type.Equals("Builder")) { Builder b = gameObject.GetComponent <Builder>(); b.enabled = true; m_MouseLook.LookRotation(transform, m_Camera.transform); this.enabled = false; changing = true; return; } } else if (Input.GetKeyDown(KeyCode.F2)) { if (!type.Equals("Dragon")) { //gameObject.AddComponent<Dragon>().Start(); Dragon d = gameObject.GetComponent <Dragon>(); d.enabled = true; m_MouseLook.LookRotation(transform, m_Camera.transform); this.enabled = false; changing = true; return; } } else if (Input.GetKeyDown(KeyCode.F3)) { if (!type.Equals("Scout")) { //gameObject.AddComponent<Scout>(); Scout s = gameObject.GetComponent <Scout>(); s.enabled = true; m_MouseLook.LookRotation(transform, m_Camera.transform); this.enabled = false; changing = true; return; } } RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; m_Jump = false; jumpstaken = 0; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
/* * SHARED */ //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>FIXED UPDATE private void FixedUpdate() { float speed = 0f; //If this is running at the local player (client with authoritative control or host client) //We run normal FPS controller (prediction) if (isLocalPlayer) { //This must be before move to check if move grounded the character m_PreviouslyGrounded = m_CharacterController.isGrounded; currentStamp = Network.time; //Store crouch input to send to server //We do this before reading input so that we can compare with the current crouch state bool sendCrouch = m_isCrouching; //Input from user or simulated if (inputSimulation) { SimInput(out speed); } else { GetInput(out speed); } //Store jump input to send to server //We need to store this here because player movement will clear m_Jump bool sendJump = m_Jump; // Store transform values //This is also used for the host to know if it moved to send change messages Vector3 prevPosition = transform.position; Quaternion prevRotation = transform.rotation; // Store collision values CollisionFlags lastFlag = m_CollisionFlags; //If we have predicion, we use the input here to move the character if (prediction) { //Move the player object PlayerMovement(speed); } //Client sound and camera ProgressStepCycle(speed); if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); } //OWNER CLIENTS THAT ARE NOT THE HOST //CLIENTS THAT ARE NOT THE SERVER if (!isServer) { bool crouchChange = m_isCrouching != sendCrouch; bool moved = Vector3.Distance(prevPosition, transform.position) > 0 || m_Input[0] || m_Input[1] || m_Input[2] || m_Input[3]; if (moved || sendJump || crouchChange || rotationChanged) { //Store all inputs generated between msgs to send to server Inputs inputs = new Inputs(); inputs.yaw = transform.rotation.eulerAngles.y; inputs.pitch = m_firstPersonCharacter.rotation.eulerAngles.x; inputs.wasd = m_Input; inputs.move = moved; inputs.walk = m_IsWalking; inputs.rotate = rotationChanged; inputs.jump = sendJump; inputs.crouch = m_isCrouching; inputs.timeStamp = currentStamp; inputsList.Enqueue(inputs); debugMovement dePos = new debugMovement(); // DEBUG POSITION dePos.velocity = m_CharacterController.velocity; dePos.position = transform.position; debugClientPos.Enqueue(dePos); //If we moved, then we need to store reconciliation if (moved || sendJump || crouchChange) { // Create reconciliation entry ReconciliationEntry entry = new ReconciliationEntry(); entry.inputs = inputs; entry.lastFlags = lastFlag; entry.position = prevPosition; entry.rotationYaw = transform.rotation.eulerAngles.y; entry.grounded = m_PreviouslyGrounded; entry.prevCrouching = m_PreviouslyCrouching; AddReconciliation(entry); } //Clear the jump to send sendJump = false; //Clear rotation flag rotationChanged = false; } } //HOST CLIENT if (isServer) { if (Vector3.Distance(transform.position, prevPosition) > 0 || rotationChanged) { movementToSend = true; } } //Thread.Sleep(7); } /* * SERVER SIDE */ else //If we are on the server, we process commands from the client instead, and generate update messages { if (isServer) { //Thread.Sleep(7); //Store state Vector3 lastPosition = transform.position; Quaternion lastCharacterRotation = transform.rotation; Quaternion lastCameraRotation = m_firstPersonCharacter.rotation; //Create the struct to read possible input to calculate Inputs inputs; inputs.rotate = false; //If we have inputs, get them and simulate on the server if (inputsList.Count > 0) { while (inputsList.Count > 0) { inputs = inputsList.Dequeue(); m_IsWalking = inputs.walk; m_Input = inputs.wasd; m_isCrouching = inputs.crouch; m_Jump = inputs.jump; currentStamp = inputs.timeStamp; //If need to, apply rotation if (inputs.rotate) { transform.rotation = Quaternion.Euler(transform.rotation.x, inputs.yaw, transform.rotation.z); m_firstPersonCharacter.rotation = Quaternion.Euler(inputs.pitch, m_firstPersonCharacter.rotation.eulerAngles.y, m_firstPersonCharacter.rotation.eulerAngles.z); } //If need to, simulate movement if (inputs.move) { //Server-side method to the speed out of input from clients CalcSpeed(out speed); //Move the player object PlayerMovement(speed); } //Check if something changed and store //This prevents movement skipping if (Vector3.Distance(transform.position, lastPosition) > 0 || inputs.rotate) { movementToSend = true; } } } m_PreviouslyGrounded = m_CharacterController.isGrounded; } } }
private void Update() { if (!isMapMode) { RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump && !m_isCrouching) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; float speed; GetInput(out speed); // always move along the camera forward as it is the direction that it being aimed at Vector3 desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x; // get a normal for the surface that is being touched to move along it RaycastHit hitInfo; Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo, m_CharacterController.height / 2f, Physics.AllLayers, QueryTriggerInteraction.Ignore); desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized; m_MoveDir.x = desiredMove.x * speed; m_MoveDir.z = desiredMove.z * speed; if (m_CharacterController.isGrounded) { m_MoveDir.y = -m_StickToGroundForce; if (m_Jump) { m_MoveDir.y = m_JumpSpeed; PlayJumpSound(); m_Jump = false; m_Jumping = true; } } else { m_MoveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime; } m_CollisionFlags = m_CharacterController.Move(m_MoveDir * Time.fixedDeltaTime); ProgressStepCycle(speed); UpdateCameraPosition(speed); m_MouseLook.UpdateCursorLock(); } }
// Update is called once per frame private void Update() { if (!isLocalPlayer) { return; } Cursor.lockState = CursorLockMode.None; Cursor.lockState = CursorLockMode.Confined; Cursor.visible = true; Camera.main.transform.position = transform.position + transform.up * 0.5f; Camera.main.transform.parent = transform; if (Input.GetKeyDown(KeyCode.Escape)) { chatUp = !chatUp; } if (!chatUp) { //equip smg if (Input.GetKeyDown(KeyCode.O)) { Debug.Log("SMG equipped"); smgE = true; pistolE = false; pistol.SetActive(false); SMG.SetActive(true); //equip pistol } else if (Input.GetKeyDown(KeyCode.P)) { Debug.Log("Pistol equipped"); smgE = false; pistolE = true; pistol.SetActive(true); SMG.SetActive(false); } //for activating power ups //testing purposes ONLY /*if (Input.GetKeyDown(KeyCode.I)) { * inventory.AddPowerUp(PowerUp.FAST_MOVE); * } * else if (Input.GetKeyDown(KeyCode.G)) { * inventory.AddPowerUp(PowerUp.DOUBLE_DAMAGE); * } * else if (Input.GetKeyDown(KeyCode.F)) { * inventory.AddPowerUp(PowerUp.FAST_FIRE); * } * else if (Input.GetKeyDown(KeyCode.B)) { * inventory.AddPowerUp(PowerUp.INVINCIBLE); * } * else if (Input.GetKeyDown(KeyCode.J)) { * inventory.AddPowerUp(PowerUp.JUMP_HIGH); * }*/ //Check if the player wishes to use a power up if (!powerActive) { if (Input.GetButtonDown("Inventory1")) { currentPower = inventory.getPowerUp(1); if (currentPower != PowerUp.NONE) { inventory.RemovePowerUp(1); powerEffect[currentPower](); powerActive = true; } } else if (Input.GetButtonDown("Inventory2")) { currentPower = inventory.getPowerUp(2); if (currentPower != PowerUp.NONE) { inventory.RemovePowerUp(2); powerEffect[currentPower](); powerActive = true; } } else if (Input.GetButtonDown("Inventory3")) { currentPower = inventory.getPowerUp(3); if (currentPower != PowerUp.NONE) { inventory.RemovePowerUp(3); powerEffect[currentPower](); powerActive = true; } } else if (Input.GetButtonDown("Inventory4")) { currentPower = inventory.getPowerUp(4); if (currentPower != PowerUp.NONE) { inventory.RemovePowerUp(4); powerEffect[currentPower](); powerActive = true; } } else if (Input.GetButtonDown("Inventory5")) { currentPower = inventory.getPowerUp(5); if (currentPower != PowerUp.NONE) { inventory.RemovePowerUp(5); powerEffect[currentPower](); powerActive = true; } } } else { powerUpTimer -= Time.deltaTime; int g = (int)powerUpTimer; powerUpTimerText.text = g.ToString(); } if (powerUpTimer <= 0.0f) { Debug.Log("Power up over"); if (currentPower == PowerUp.INVINCIBLE) { health.SwitchInvincibility(); } powerUpTimerText.text = ""; m_WalkSpeed = 8; m_JumpSpeed = 6; nextFireP = 0.7f; nextFireS = 0.1f; powerUpTimer = 10.0f; currentPower = PowerUp.NONE; doubleDamageVar = false; powerActive = false; } //countdown timer to allow the player to shoot again its just always subtracting and resets when the player shoots nextFireP -= Time.deltaTime; nextFireS -= Time.deltaTime; //used to fire the guns if (Input.GetButton("Fire1")) { if (smgE && nextFireS <= 0.0f) { CmdfireBullet(); //timer until can shoot again if (currentPower == PowerUp.FAST_FIRE) { nextFireS = 0.05f; } else { nextFireS = 0.1f; } } else if (pistolE && nextFireP <= 0.0f) { CmdfireBullet(); //timer until can shoot again if (currentPower == PowerUp.FAST_FIRE) { nextFireP = 0.35f; } else { nextFireP = 0.7f; } } } RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; } }
// Update is called once per frame private void Update() { if (Character.Health.IsAlive && transform.position.y < m_killHeight) { Character.Health.Kill(); } //Rotate to face mouse m_playerLook.LookRotation(transform, RotatePoint); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = Input.GetButtonDown("Jump"); } if (Input.GetMouseButton(1)) { MainCamera.fieldOfView = m_aimingFOV; } else { MainCamera.fieldOfView = m_normalFOV; } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; if (!m_isWalking && !m_isIdle) { CurrentStamina = Mathf.Clamp(CurrentStamina - (StaminaDecreasePerFrame * Time.deltaTime), 0.0f, MaxStamina); StaminaRegenTimer = 0.0f; } else if (CurrentStamina < MaxStamina) { if (StaminaRegenTimer >= StaminaTimeToRegen) { CurrentStamina = Mathf.Clamp(CurrentStamina + (StaminaIncreasePerFrame * Time.deltaTime), 0.0f, MaxStamina); } else { StaminaRegenTimer += Time.deltaTime; } } if (m_isIdle & m_CharacterController.isGrounded) { Character.Animator.SetBool("Running", false); Character.Animator.SetBool("Walking", false); Character.Animator.SetBool("Jumping", false); } else { if (m_Jumping) { Character.Animator.SetBool("Jumping", true); Character.Animator.SetBool("Running", false); Character.Animator.SetBool("Walking", false); } else { Character.Animator.SetBool("Jumping", false); Character.Animator.SetBool("Running", !m_isWalking); Character.Animator.SetBool("Walking", m_isWalking); } } if (Character.Health.CurrentHealth < Character.Health.MaxHealth) { if (HealthRegenTimer >= HealthTimeToRegen) { Character.Health.Heal((HealthIncreasePerFrame * Time.deltaTime)); Character.Health.CurrentHealth = Mathf.Clamp(Character.Health.CurrentHealth + (HealthIncreasePerFrame * Time.deltaTime), 0.0f, Character.Health.MaxHealth); } else { HealthRegenTimer += Time.deltaTime; } } }
// Update is called once per frame private void Update() { if (Input.GetKeyDown(KeyCode.Z)) { hidemouse = !hidemouse; } if (hidemouse == true) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } if (hidemouse == false) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } if (mIsControlEnabled) { // Interact with the item if (mInteractItem != null && Input.GetKeyDown(KeyCode.F)) { // Interact animation mInteractItem.OnInteractAnimation(_animator); } // Execute action with item if (mCurrentItem != null && Input.GetMouseButtonDown(0)) { // Dont execute click if mouse pointer is over uGUI element if (!EventSystem.current.IsPointerOverGameObject()) { // TODO: Logic which action to execute has to come from the particular item _animator.SetTrigger("attack_1"); } } RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; _animator.SetBool("is_in_air", true); } if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0)) { _animator.SetBool("is_in_air", false); _animator.SetBool("run", true); } else { _animator.SetBool("run", false); } m_PreviouslyGrounded = m_CharacterController.isGrounded; } }
public void OnLanding() { StartCoroutine(jumpBob.DoBobCycle()); animator.SetInteger("Jumping", 0); PlayLandingSound(); }
// Update is called once per frame private void Update() { if (gameOver) { SceneManager.LoadScene("EndScreen"); } //set the character to be on the roof if ((m_CharacterController.collisionFlags == CollisionFlags.Above)) { isOnRoof = true; } else { isOnRoof = false; } //rotate view used for mouse input //RotateView (); // the jump state needs to read here to make sure it is not missed //if the player isnt jumping and the player presses the jump button, set jump to true if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } //if the player was not grounded or on roof last frame but is in the current frame../ if ((!m_PreviouslyGrounded && m_CharacterController.isGrounded) || (!m_PreviouslyOnRoof && isOnRoof)) { //start the jump bob cycle, play the landing sound, set the vertical movement to 0 and set it so the player isnt jumping StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } //if the character is not on the ground and is not jumping but was previously grounded, set the vertical movement to 0 if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } //same as above but for on roof if (!isOnRoof && !m_Jumping && m_PreviouslyOnRoof) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; m_PreviouslyOnRoof = isOnRoof; if (Input.GetKeyDown(KeyCode.F)) { GrabObject(); } RaycastHit hit; int layerMask = 1 << 8; layerMask = ~layerMask; Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.up, out hit, m_CharacterController.height, layerMask, QueryTriggerInteraction.Ignore); if (hit.transform != null) { if ((m_CharacterController.isGrounded || isOnRoof) && hit.collider.gameObject.tag == "Killable") { gameOver = true; playerDied = true; } } if (m_CharacterController.transform.position.y < -5) { playerDied = true; gameOver = true; } }
// Update is called once per frame private void Update() { RotateView(); if (MouseOnly) { return; } // the jump state needs to read here to make sure it is not missed if (!m_Jump && !Cursor.visible) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (Cursor.visible) { m_Ascending = false; m_Descending = false; } else { m_Ascending = CrossPlatformInputManager.GetButton("Ascend"); m_Descending = CrossPlatformInputManager.GetButton("Descend"); } if (m_Ascending || m_Descending) { if (!m_PreviouslyFlying && OnStartFlying != null) { OnStartFlying(); } m_Flying = true; m_PreviouslyFlying = true; } //cancel flying if (m_Jump) { m_PreviouslyFlying = false; } //reset jump to false if we weren't on the ground if (!m_CharacterController.isGrounded) { m_Jump = false; } else { m_Flying = false; } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { if (OnLand != null) { OnLand(); } StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; m_Flying = false; m_PreviouslyFlying = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
// Update is called once per frame private void Update() { if (attacking) { attackTimer -= Time.deltaTime; if (attackTimer <= 0) { attacking = false; } } else if (Input.GetKey(KeyCode.F)) { attacking = true; attackTimer = 1.2f; //GetComponent<Animator>().SetTrigger("Attack"); } if (mIsControlEnabled) { // Interact with the ite // Execute action with item if (mCurrentItem != null && Input.GetMouseButtonDown(0)) { // Dont execute click if mouse pointer is over uGUI element if (!EventSystem.current.IsPointerOverGameObject()) { // TODO: Logic which action to execute has to come from the particular item _animator.SetTrigger("attack_1"); } } RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; _animator.SetBool("is_in_air", true); } if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0)) { _animator.SetBool("is_in_air", false); _animator.SetBool("run", true); } else { _animator.SetBool("run", false); } m_PreviouslyGrounded = m_CharacterController.isGrounded; } }
/// <summary> /// /// </summary> public override void OnUpdate() { Velocity = m_CharacterController.velocity; VelocityMagnitude = Velocity.magnitude; RotateView(); if (Finish) { return; } if (!bl_UtilityHelper.GetCursorState) { return; } // the jump state needs to read here to make sure it is not missed #if INPUT_MANAGER if (!m_Jump && State != PlayerState.Crouching) { m_Jump = bl_Input.GetKeyDown("Jump"); } if (State != PlayerState.Jumping) { if (bl_Input.GetKeyDown("Crouch")) { Crounching = !Crounching; if (Crounching) { State = PlayerState.Crouching; } else { State = PlayerState.Idle; } } } #else if (!m_Jump && State != PlayerState.Crouching) { m_Jump = Input.GetKeyDown(KeyCode.Space); } if (State != PlayerState.Jumping) { if (Input.GetKeyDown(KeyCode.C)) { Crounching = !Crounching; if (Crounching) { State = PlayerState.Crouching; } else { State = PlayerState.Idle; } } } #endif if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; State = PlayerState.Idle; bl_EventHandler.OnSmallImpactEvent(); } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } Crouch(); m_PreviouslyGrounded = m_CharacterController.isGrounded; }
// Update is called once per frame private void Update() { RotateView(); // the jump state needs to read here to make sure it is not missed if (!m_Jump) { m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); } if (CrossPlatformInputManager.GetButtonDown("X Button")) { UIEnabled = !UIEnabled; fpsCanvas.gameObject.SetActive(UIEnabled); } if (CrossPlatformInputManager.GetButtonDown("B Button")) { av.setTo2DTopDown(); } if (UIEnabled) { rtVal = CrossPlatformInputManager.GetAxis("Right Trigger"); if (rtVal != 0.0) { rayTarget = m_Camera.ScreenPointToRay(new Vector3(Screen.width / 2, (Screen.height / 2), 0)); if (Physics.Raycast(rayTarget, out hitTarget)) { //changes the material color of whatever it hit. (hitTarget.collider.gameObject.GetComponentInChildren <MeshRenderer>()).sharedMaterial = pallet[tracerLocTexture]; } } if (CrossPlatformInputManager.GetButtonDown("A Button")) { rayTarget = m_Camera.ScreenPointToRay(new Vector3(Screen.width / 2, (Screen.height / 2), 0)); if (Physics.Raycast(rayTarget, out hitTarget)) { Vector3 dir = rayTarget.direction; Painting p = Instantiate(paintings[tracerLocPaint]); p.transform.position = hitTarget.point; p.transform.rotation = Quaternion.FromToRotation(Vector3.up, new Vector3(0, hitTarget.point.y, 0)); dm.addPainting(p); // Sliding into those dm's } } if (CrossPlatformInputManager.GetButtonDown("Right Bumper")) { // makes sure it doesn't go past the textures list length tracerLocTexture = (tracerLocTexture + 1) % pallet.Count; textureTracer.updateSelection(tracerLocTexture); } if (CrossPlatformInputManager.GetButtonDown("Left Bumper")) { // makes sure it doesn't go under 0 tracerLocTexture = ((tracerLocTexture - 1) + pallet.Count) % pallet.Count; textureTracer.updateSelection(tracerLocTexture); } dVal = CrossPlatformInputManager.GetAxis("DVert"); //Debug.Log(Time.time - lastTime); if (Time.time - lastTime > 0.1125f) { if (dVal < 0) { tracerLocPaint = (tracerLocPaint + 1) % paintings.Count; paintTracer.updateSelection(tracerLocPaint); } else if (dVal > 0) { tracerLocPaint = ((tracerLocPaint - 1) + paintings.Count) % paintings.Count; paintTracer.updateSelection(tracerLocPaint); } lastTime = Time.time; } } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; }