private void Awake() { Cursor.lockState = CursorLockMode.Locked; _pi = new PlayerInputClass(); _cameras = transform.Find("CameraHolder"); if (_cameras == null) { Debug.LogError("Camera holder not attached!"); } }
private void Awake() { _pi = new PlayerInputClass(); _pi.Player.Move.performed += context => movementInput = context.ReadValue <Vector2>(); _cc = GetComponent <CharacterController>(); if (_cc == null) { Debug.LogError("No Character Controller attached!"); } jumpVelocity = _gravity; isMoving = false; }
// Start is called before the first frame update void Awake() { inputState = new PlayerInputClass(); playerCamera = GetComponentInChildren <Camera>(); #if UNITY_EDITOR || UNITY_STANDALONE if (lockCursor) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } #endif }
// Update is called once per frame void FixedUpdate() { PlayerInputClass inputState = manager.PlayerInputState; HealingGun.ammunition.UpdateHealthPackAmmo(); if (inputState != null) { if (inputState.Switch) { if (HealingGun.gameObject.activeSelf) { HealingGun.Shoot(); } else if (!switchingWeapons) { SwitchWeapon(); } } if (inputState.Swap) { WeaponPickup p = manager.GetPickup(); if (!HealingGun.gameObject.activeSelf && p != null) { int c = p.AmmoInClip; int a = p.ammo; Debug.Log("Swapping: (" + c.ToString() + "," + a.ToString() + ")"); if (p.nonreloadable && p.worldSpawned && PowerupManager.GetPowerupStatus(Powerups.ExtraAmmo)) { c += Mathf.CeilToInt((float)c / 4); } bool taken = SwapWeapon(p.weaponType, p.transform, a, c); if (taken) { p.TakePickup(); } } } if (inputState.Heal && HealingGun.ammunition.remainingAmmo > 0 && playerHealth.currentHealth < playerHealth.maxHealth - 1) { if (!switchingWeapons) { SwitchWeapon(HealingGun, GetCurrentWeapon()); } } } }
void MovePlayer(float updateDeltaTime) { //get the input PlayerInputClass inputState = manager.PlayerInputState; Vector2 moveInput = new Vector2(); float camXinput = 0; float moveMag = 0; if (inputState != null) { moveInput = inputState.MoveInput; inputDirection.x = moveInput.x; inputDirection.y = moveInput.y; camXinput = inputState.CameraX; if (camXinput > maxAimAssistAmount) { maxAimAssistAmount = camXinput; } inputDirection.z = camXinput; moveMag = moveInput.magnitude; } //translate input to 3d vector Vector3 forwardVector = transform.forward * moveInput.y; Vector3 horizontalVector = transform.right * moveInput.x; Vector3 moveVector = Vector3.Normalize(forwardVector + horizontalVector); //rotate float x = camXinput * mouseSensitivity; bool dirtyAim = false; int multiTarget = 0; float utilisedAssist = (moveMag > 0.5f)? movingAimAssistAmount : aimAssistAmount; #if !UNITY_STANDALONE_WIN if (manager.slowDownAim) { foreach (AimAssistEnemy enemy in manager.enemiesInSights) { if (multiTarget == 0) { multiTarget++; //normalised value of angle to target (bigger when closer) float m = manager.aimSlowDownAngle - Mathf.Abs(enemy.angle); m = m / manager.aimSlowDownAngle; //apply linear slow down float absNewX = Mathf.Min(Mathf.Lerp(Mathf.Abs(x), aimAssistSlowSpeed, m), Mathf.Abs(x)); x = (x > 0) ? absNewX : -absNewX; if (Mathf.Abs(x) < maxAimAssistAmount * 0.1f || (x > 0 && enemy.angle > 0) || (x < 0 && enemy.angle < 0)) { ++multiTarget; float assist = Mathf.Max(0, Mathf.Lerp(aimAssistAmount, assistWell, m)); curAimAssist = Mathf.Lerp(curAimAssist, (enemy.angle > 0) ? assist : -assist, aimAssistLerp.x * updateDeltaTime); } } } /*if(!dirtyAim) * { * curAimAssist = Mathf.Lerp(curAimAssist, 0, aimAssistLerp * updateDeltaTime); * } * else if(multiTarget == 1) * x += curAimAssist;*/ } else { if (Mathf.Abs(curAimAssist) > 0.01f && Mathf.Abs(x) > 0.01f) { curAimAssist = Mathf.Lerp(curAimAssist, 0, aimAssistLerp.y * updateDeltaTime); } else { curAimAssist = 0; } } x += curAimAssist; #endif if (mouseAcceleration > 0) { if (Mathf.Abs(x) > 0.1f) { currentTurn = Mathf.Lerp(currentTurn, x, mouseAcceleration * updateDeltaTime); } else { currentTurn = Mathf.Lerp(currentTurn, x, mouseAcceleration * updateDeltaTime /* * 4*/); } } else { currentTurn = x; } transform.Rotate(0, currentTurn, 0); //move Vector3 resultingVelocity = currentVelocity; resultingVelocity.y = 0; float currentSpeed = resultingVelocity.magnitude; if (moveMag > 0.15f) { if (currentSpeed > snapThreshold && (Vector3.Angle(moveVector, currentVelocity) < 90 || moveInput.y > 0.7f)) { resultingVelocity += moveVector * acceleration * 6 * updateDeltaTime; } else { resultingVelocity += moveVector * acceleration * updateDeltaTime; } } else { if (currentSpeed < stoppingThreshold) { resultingVelocity = Vector3.zero; } else { resultingVelocity = Vector3.Lerp(resultingVelocity, Vector3.zero, decceleration * updateDeltaTime); } } resultingVelocity = Vector3.ClampMagnitude(resultingVelocity, speed); resultingVelocity.y = -10; currentVelocity = resultingVelocity; MoveController(updateDeltaTime); }
private void Awake() { _currentHealth = _maxHealth; _pi = new PlayerInputClass(); }