private void Update() { // handle shooting SpellController basicSpell = m_SpellSlots[basicSpellIndex]; basicSpell.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); SpellController altSpell = m_SpellSlots[altSpellIndex]; altSpell.HandleShootInputs( m_InputHandler.GetAltInputDown(), m_InputHandler.GetAltInputHeld(), m_InputHandler.GetAltInputReleased()); SpellController utilitySpell = m_SpellSlots[utilitySpellIndex]; utilitySpell.HandleShootInputs( m_InputHandler.GetUtilityInputDown(), m_InputHandler.GetUtilityInputHeld(), m_InputHandler.GetUtilityInputReleased()); SpellController ultimateSpell = m_SpellSlots[ultimateSpellIndex]; ultimateSpell.HandleShootInputs( m_InputHandler.GetUltimateInputDown(), m_InputHandler.GetUltimateInputHeld(), m_InputHandler.GetUltimateInputReleased()); SpellController interactSpell = interactionController; interactSpell.HandleShootInputs( m_InputHandler.GetInteractInputDown(), m_InputHandler.GetInteractInputHeld(), m_InputHandler.GetInteractInputReleased()); // Pointing at enemy handling // isPointingAtEnemy = false; // if(Physics.Raycast(SpellCamera.transform.position, SpellCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) // { // if(hit.collider.GetComponentInParent<EnemyCharacterController>()) // { // isPointingAtEnemy = true; // } // } }
private void Update() { // shoot handling WeaponController activeWeapon = GetActiveWeapon(); if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); // Handle accumulating recoil if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); } } // weapon switch handling if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } }
private void Update() { // shoot handling WeaponController activeWeapon = GetActiveWeapon(); if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); // Handle accumulating recoil if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); } } // weapon switch handling if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } // Pointing at enemy handling isPointingAtEnemy = false; if (activeWeapon) { if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) { //if (hit.collider.GetComponentInParent<EnemyController>()) //{ // isPointingAtEnemy = true; //} } } }
// Update is called once per frame void Update() { HandleCharacterMovement(); HandleShooting(m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); }
private void Update() { // shoot handling WeaponController activeWeapon = GetActiveWeapon(); //GUESS IS we'll only get the aim and set fired state if weapon is up aka working if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights //GUESS: is aiming will be true if we're aiming at something in the game and we can fire at it isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), //TODO I thought it fires when you hold the trigger, research naming convention and meaning behind get fire input released m_InputHandler.GetFireInputReleased()); // Handle accumulating recoil //TODO Recoil? if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); } } // weapon switch handling if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && //this condition contradicts previous assumption about weapon down meaning non fireable - TODO pin down each enums intended effect (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } // Pointing at enemy handling isPointingAtEnemy = false; if (activeWeapon) { //Assumption is ray case return true if trajectory of weappon triggered projectile is expected to hit the bot if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) { if (hit.collider.GetComponentInParent <EnemyController>()) { isPointingAtEnemy = true; } } } }
private void Update() { //Load stuff on first frame instead of Start() to ensure required components have been initialized if (!isLoaded) { // Load weapons once HUD is ready for (int i = 0; i < m_WeaponSlots.Length; i++) { if (PlayerPrefs.HasKey($"m_WeaponSlots[{i}]")) { var weaponName = PlayerPrefs.GetString($"m_WeaponSlots[{i}]"); GameObject weaponPrefab = WeaponGenerator.getWeaponGameObject(weaponName); if (weaponPrefab) { WeaponController weaponController = (WeaponController)weaponPrefab.GetComponentInChildren(typeof(WeaponController)); AddWeapon(weaponController, weaponName); } } } if (!hasWeapons) { var weaponName = "milk"; GameObject weaponPrefab = WeaponGenerator.getWeaponGameObject(weaponName); if (weaponPrefab) { WeaponController weaponController = (WeaponController)weaponPrefab.GetComponentInChildren(typeof(WeaponController)); AddWeapon(weaponController, weaponName); } } if (PlayerPrefs.HasKey("activeWeaponIndex")) { SwitchToWeaponIndex(PlayerPrefs.GetInt("activeWeaponIndex")); } else { SwitchWeapon(true); } isLoaded = true; } // shoot handling WeaponController activeWeapon = GetActiveWeapon(); if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); // Handle accumulating recoil if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); } } // weapon switch handling if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } // Pointing at enemy handling isPointingAtEnemy = false; if (activeWeapon) { if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) { if (hit.collider.GetComponentInParent <EnemyController>()) { isPointingAtEnemy = true; } } } WeaponDropper(); }
private void Update() { // shoot handling //撮影処理 WeaponController activeWeapon = GetActiveWeapon(); if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights //下向きの照準を処理します isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting //射撃を処理する bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); // Handle accumulating recoil //蓄積された反動を処理します if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; //蓄積反動 += 3Dベクトルを返す。* アクティブな武器.反動力; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); //蓄積反動 = 3Dベクトル。 クランプの大きさ(累積反動、最大反動距離); } } // weapon switch handling //武器切り替え処理 if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } // Pointing at enemy handling //敵の扱いを指さす isPointingAtEnemy = false; //敵を指している = 非表示 if (activeWeapon) //もし、アクティブな武器 { if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) //もし(物理レイキャスト(武器カメラ.変換.位置, 武器カメラ.変換.先端,外レイキャストヒット, 1000,-1,クエリはトリガーの発生を報告しません)) { if (hit.collider.GetComponentInParent <EnemyController>()) //もし(ヒット.コライダー.コンポーネントを親から取得<EnemyController>) { isPointingAtEnemy = true; //敵を指している = 表示 } } } }
void HandleCharacterMovement() { // horizontal character rotation { // rotate the transform with the input speed around its local Y axis transform.Rotate(new Vector3(0f, (m_InputHandler.GetLookInputsHorizontal() * rotationSpeed * RotationMultiplier), 0f), Space.Self); } // vertical camera rotation { // add vertical inputs to the camera's vertical angle m_CameraVerticalAngle += m_InputHandler.GetLookInputsVertical() * rotationSpeed * RotationMultiplier; // limit the camera's vertical angle to min/max m_CameraVerticalAngle = Mathf.Clamp(m_CameraVerticalAngle, -89f, 89f); // apply the vertical angle as a local rotation to the camera transform along its right axis (makes it pivot up and down) playerCamera.transform.localEulerAngles = new Vector3(m_CameraVerticalAngle, 0, 0); } // character movement handling bool isSprinting = m_InputHandler.GetSprintInputHeld(); { if (isSprinting) { isSprinting = SetCrouchingState(false, false); } float speedModifier = isSprinting ? sprintSpeedModifier : 1f; // float speedModifier = sprintSpeedModifier; // converts move input to a worldspace vector based on our character's transform orientation Vector3 worldspaceMoveInput = transform.TransformVector(m_InputHandler.GetMoveInput()); if (m_InputHandler.GetJumpInputDown()) { m_JumpBuffer = totalJumpBufferFrames; } float jumpSpeedBoost = (maxJumpSpeedBoost - 1f) * m_JumpBoostCharge + 1f; // handle grounded movement if (isGrounded) { //linear interpolate bewteen 1 and jumpSpeedBoost using t = m_JumpBoostDuration/jumpBoostDuration float lerpedSpeedBoost = (jumpSpeedBoost - 1) * m_JumpBoostDuration / jumpBoostDuration + 1; // calculate the desired velocity from inputs, max speed, and current slope Vector3 targetVelocity; if (m_InputHandler.GetFireInputHeld()) { targetVelocity = worldspaceMoveInput * maxSpeedOnGround * speedModifier * lerpedSpeedBoost; } else { targetVelocity = worldspaceMoveInput * maxSpeedOnGround * speedModifier * lerpedSpeedBoost * m_PlayerUpgradeManager.nonShootingSpeedModifier; } // reduce speed if crouching by crouch speed ratio if (isCrouching) { targetVelocity *= maxSpeedCrouchedRatio; } targetVelocity = GetDirectionReorientedOnSlope(targetVelocity.normalized, m_GroundNormal) * targetVelocity.magnitude; // smoothly interpolate between our current velocity and the target velocity based on acceleration speed characterVelocity = Vector3.Lerp(characterVelocity, targetVelocity, movementSharpnessOnGround * Time.deltaTime); // jumping // if (isGrounded && m_InputHandler.GetJumpInputDown()) if (isGrounded && m_JumpBuffer > 0) { //build up the bunny hopping jump boost if (m_JumpBoostCharge < 1f) { m_JumpBoostCharge += 0.2f; } // force the crouch state to false if (SetCrouchingState(false, false)) { // start by canceling out the vertical component of our velocity characterVelocity = new Vector3(characterVelocity.x, 0f, characterVelocity.z); // then, add the jumpSpeed value upwards characterVelocity += Vector3.up * jumpForce; // play sound audioSource.PlayOneShot(jumpSFX); // remember last time we jumped because we need to prevent snapping to ground for a short time m_LastTimeJumped = Time.time; hasJumpedThisFrame = true; // Force grounding to false isGrounded = false; m_GroundNormal = Vector3.up; } } // footsteps sound float chosenFootstepSFXFrequency = (isSprinting ? footstepSFXFrequencyWhileSprinting : footstepSFXFrequency); if (m_footstepDistanceCounter >= 1f / chosenFootstepSFXFrequency) { m_footstepDistanceCounter = 0f; audioSource.PlayOneShot(footstepSFX); } // keep track of distance traveled for footsteps sound m_footstepDistanceCounter += characterVelocity.magnitude * Time.deltaTime; } // handle air movement else { // add air acceleration characterVelocity += worldspaceMoveInput * accelerationSpeedInAir * Time.deltaTime * jumpSpeedBoost; // characterVelocity += worldspaceMoveInput * accelerationSpeedInAir * speedModifier Time.deltaTime; // limit air speed to a maximum, but only horizontally float verticalVelocity = characterVelocity.y; Vector3 horizontalVelocity = Vector3.ProjectOnPlane(characterVelocity, Vector3.up); // horizontalVelocity = Vector3.ClampMagnitude(horizontalVelocity, maxSpeedInAir * speedModifier); if (!m_InputHandler.GetFireInputHeld()) { horizontalVelocity = Vector3.ClampMagnitude(horizontalVelocity, maxSpeedOnGround * speedModifier * jumpSpeedBoost * m_PlayerUpgradeManager.nonShootingSpeedModifier); } else { horizontalVelocity = Vector3.ClampMagnitude(horizontalVelocity, maxSpeedOnGround * speedModifier * jumpSpeedBoost); } characterVelocity = horizontalVelocity + (Vector3.up * verticalVelocity); // apply the gravity to the velocity characterVelocity += Vector3.down * gravityDownForce * Time.deltaTime; } } if (m_JumpBuffer > 0) { m_JumpBuffer--; } // apply the final calculated velocity value as a character movement Vector3 capsuleBottomBeforeMove = GetCapsuleBottomHemisphere(); Vector3 capsuleTopBeforeMove = GetCapsuleTopHemisphere(m_Controller.height); m_Controller.Move(characterVelocity * Time.deltaTime); // detect obstructions to adjust velocity accordingly m_LatestImpactSpeed = Vector3.zero; //layermask will account for layers 1-9: 1111 1111 1110 = 4094 if (Physics.CapsuleCast(capsuleBottomBeforeMove, capsuleTopBeforeMove, m_Controller.radius, characterVelocity.normalized, out RaycastHit hit, characterVelocity.magnitude * Time.deltaTime, _layerMask, QueryTriggerInteraction.Ignore)) { // We remember the last impact speed because the fall damage logic might need it m_LatestImpactSpeed = characterVelocity; characterVelocity = Vector3.ProjectOnPlane(characterVelocity, hit.normal); } }
private void Update() { // shoot handling WeaponController activeWeapon = GetActiveWeapon(); if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up) { // handle aiming down sights // isAiming = m_InputHandler.GetAimInputHeld(); // handle shooting bool hasFired = activeWeapon.HandleShootInputs( m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased()); bool hasAltFired = activeWeapon.HandleAltShootInputs( m_InputHandler.GetAltFireInputDown(), m_InputHandler.GetAltFireInputHeld(), m_InputHandler.GetAltFireInputReleased()); // Handle accumulating recoil if (hasFired) { m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce; m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance); } // tell weaponcontroller to use lightning VFX if (m_InputHandler.GetFireInputDown()) { activeWeapon.SetFX(true); } else if (m_InputHandler.GetFireInputReleased()) { activeWeapon.SetFX(false); } } // weapon switch handling if (!isAiming && (activeWeapon == null || !activeWeapon.isCharging) && (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down)) { int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput(); if (switchWeaponInput != 0) { bool switchUp = switchWeaponInput > 0; SwitchWeapon(switchUp); } else { switchWeaponInput = m_InputHandler.GetSelectWeaponInput(); if (switchWeaponInput != 0) { if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null) { SwitchToWeaponIndex(switchWeaponInput - 1); } } } } // Pointing at enemy handling isPointingAtEnemy = false; if (activeWeapon) { if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore)) { if (hit.collider.GetComponentInParent <EnemyController>()) { isPointingAtEnemy = true; } } } // Selectable handling Collider selectableCollider = RaycastForSelectableCollider(); if (selectableCollider) { Selectable selectable = selectableCollider.gameObject.GetComponentInParent <Selectable>(); //if pointing at a selectable and it hasn't been selected, select it and unselect the last used selectable if (!selectable.selected) { // Debug.Log("select"); selectable.Select(GetComponent <PlayerUpgradeManager>()); m_LastSelectable = selectable; } } else if (m_LastSelectable) { //if not pointing at a selectable and we were in the last frame, then unset m_lastselectable and unselect it m_LastSelectable.Unselect(); m_LastSelectable = null; } }