private bool InternalShootRegular() { if (!BulletInChamber) { Debug.LogWarning($"Gun {Item.Name} has no bullet in the chamber but the shoot animation played..."); return(false); } // Remove the bullet from the chamber. BulletInChamber = false; // Spawn the bullet. if (BulletPrefab != null && Muzzle != null) { for (int i = 0; i < BulletsPerShot; i++) { var spawned = PoolObject.Spawn(BulletPrefab); spawned.transform.position = Muzzle.position; // Velocity is calculated based on random angle - most rifles have zero random angle. // Note that velocity magnitude is always maintained. const float MUZZLE_VELOCITY = 350f; if (BulletRandomAngle.Min == 0f && BulletRandomAngle.Max == 0) { spawned.Velocity = Muzzle.forward * MUZZLE_VELOCITY; } else { float angle = BulletRandomAngle.Lerp(Random.value); spawned.Velocity = GenerateConeDirection(angle, Muzzle) * MUZZLE_VELOCITY; Debug.DrawLine(Muzzle.position, Muzzle.position + spawned.Velocity.normalized, Color.red, 10f); } } } // Auto re-chamber. For some weapons, such as bolt-action rifles, this is not desirable. This will be implemented later. Rechamber(); // Spawn muzzle flash. if (Muzzle != null && MuzzleFlashPrefab != null) { var spawned = PoolObject.Spawn(MuzzleFlashPrefab); spawned.transform.SetParent(Muzzle); spawned.transform.localPosition = Vector3.zero; spawned.transform.localRotation = Quaternion.identity; spawned.transform.Rotate(0f, 0f, Random.Range(0f, 360f), Space.Self); } if (SpawnCasingOnShoot) { // Spawn bullet casing. SpawnCasing(); } // Add kick and recoil. AddRecoil(); return(true); }
private void UpdateMovement() { _velocity += Vector2.down * _gravity * Time.deltaTime; float vertical = Mathf.Clamp01(_rewiredPlayer.GetAxisRaw("Vertical")); float acceleration = _acceleration * _accelerationFactorRange.Lerp(1 - Vector2.Dot(transform.up, _velocity.normalized)); _velocity += (Vector2)transform.up * vertical * acceleration * Time.deltaTime; _velocity = Vector2.ClampMagnitude(_velocity, _terminalVelocity); }
// Update is called once per frame void Update() { if (_rb.velocity.magnitude > _velocityLimits.min) { float velocityN = Mathf.Clamp(_velocityLimits.InverseLerp(_rb.velocity.magnitude), 0, 1); float emission = _emissionRange.Lerp(velocityN); _particleSystem.Emit((int)emission); } }
// ---- Position ---- void updatePosition() { // set zoom amount, smoothed // get the normalized distance between the zoom limits, then ease it. _targetDistN = _distanceLimits.InverseLerp(Vector3.Distance(_targetPos, transform.position)); if (_zoomSpeedEasing.keys.Length > 0) { _targetDistN = _zoomSpeedEasing.Evaluate(_targetDistN); } _desiredDistance += _inputState.zoom * Time.deltaTime * _zoomSpeed.Lerp(_targetDistN); _desiredDistance = _distanceLimits.ClampValue(_desiredDistance); _currDistance = Mathf.Lerp(_currDistance, _desiredDistance, Time.deltaTime * _zoomDampening); // calculate position based on the new distance transform.position = _targetPos - (transform.forward * _currDistance) + _targetOffset; }