// Update is called once per frame void Update() { ammoSlider.Set(WeaponController.GetAmmo()); Vector3 forward = cam.transform.forward; forward.y = 0; forward = forward.normalized; Vector3 right = new Vector3(forward.z, 0, -forward.x); float horizontalAxis = Input.GetAxis("Horizontal"); float verticalAxis = Input.GetAxis("Vertical"); Quaternion rotation = Quaternion.AngleAxis(10 * Mathf.Abs(horizontalAxis) * moveSpeed * Time.deltaTime, Vector3.up); //move = (horizontalAxis * right) + (verticalAxis * forward); //animate.SetBool("isGrounded", cont.isGrounded); float ydir = move.y; move = (forward * verticalAxis) + (right * horizontalAxis); move = rotation * move; move = move.normalized * moveSpeed; move.y = ydir; if (wasJumpPressed) { timecounter += (Time.deltaTime); if (timecounter > delayJumpTime && !jumpExecuted) { move.y = jumpForce; jumpExecuted = true; } } if (jumpExecuted && cont.isGrounded && timecounter > delayJumpTime + .5f) { // player has jumped and landed wasJumpPressed = false; jumpExecuted = false; animate.SetBool("wasJumpPressed", false); timecounter = 0.0f; } if (Input.GetButtonDown("Jump") && cont.isGrounded) { if (!move.Equals(cont.isGrounded)) { // audio SFX SoundManagerScript.PlayOneShot("jump"); } animate.SetBool("wasJumpPressed", true); wasJumpPressed = true; // move.y = jumpForce; } move.y += Physics.gravity.y * gravityScale; if (Mathf.Abs(verticalAxis) + Mathf.Abs(horizontalAxis) > 0.1f) { animate.SetBool("isRunning", true); } else { animate.SetBool("isRunning", false); } if (wasAttackButtonPressed) { attackTimeCounter += (Time.deltaTime); if (attackTimeCounter > delayAttackTime) { FireWeapon(); } } if (Input.GetKeyDown(KeyCode.Alpha1) && !wasAttackButtonPressed) { WeaponController.SetActiveWeaponMode("standard"); } if (Input.GetKeyDown(KeyCode.Alpha2) && !wasAttackButtonPressed) { WeaponController.SetActiveWeaponMode("Flames"); } if (Input.GetKeyDown(KeyCode.Alpha3) && !wasAttackButtonPressed) { WeaponController.SetActiveWeaponMode("AcidSpray"); } if (Input.GetKeyDown(KeyCode.Alpha4) && !wasAttackButtonPressed) { WeaponController.SetActiveWeaponMode("Lightning"); } if (Input.GetButtonDown("Fire1") && !isPaused && !wasAttackButtonPressed && WeaponController.GetAmmoAvaliable() > 0) { animate.SetBool("isAttacking", true); wasAttackButtonPressed = true; } if (WeaponController.GetAmmoAvaliable() <= 0) { stopFireWeapon(); } if (Input.GetButtonUp("Fire1")) { stopFireWeapon(); animate.SetBool("isAttacking", false); attackTimeCounter = 0; wasAttackButtonPressed = false; } cont.Move(move * Time.deltaTime); //transform.Rotate(rotation.eulerAngles); transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(transform.forward, new Vector3(move.x, 0f, move.z), moveSpeed * rotateSpeed * Time.deltaTime, 0f)); animate.SetFloat("playerLife", playerHealth.currentHealth); if (transform.position.y <= -100) { respawn(); } }