public void MakePlayerMoveToDestination(Vector3 targetPosition) { float currentBelief = BeliefController.Instance.CurrentBeliefAmount; float maxBelief = BeliefController.Instance.MaxBeliefAmount; float beliefRatio = currentBelief / maxBelief; float mappedClickWeight = ExtensionFunctions.Map(beliefRatio, 0, 1, minPlayerClickWeight, 1); float maxModifierWeight = mappedClickWeight; PlayerMovementInterestModifier maxModifier = null; foreach (PlayerMovementInterestModifier playerMovementInterestModifier in _playerMovementInterestModifiers) { if (playerMovementInterestModifier.CanModifierAffect(maxModifierWeight)) { maxModifierWeight = playerMovementInterestModifier.InterestModifierWeight; maxModifier = playerMovementInterestModifier; } } if (!maxModifier) { playerMovement.MovePlayerToPosition(targetPosition); } else { playerMovement.MovePlayerToPosition(maxModifier.GetTargetPosition()); maxModifier.SetModifierUsed(); } }
public static float CheckTargetInsideFOV(Transform target, float minimumDetectionDistance, float maxLookAngle, Transform lookingPoint) { if (target == null) { return(-1); } float distanceToPlayer = Vector3.Distance(target.position, lookingPoint.position); if (distanceToPlayer > minimumDetectionDistance) { return(-1); } Vector3 modifiedPlayerPosition = new Vector3(target.position.x, 0, target.position.z); Vector3 modifiedLookingPosition = new Vector3(lookingPoint.position.x, 0, lookingPoint.position.z); Vector3 lookDirection = modifiedPlayerPosition - modifiedLookingPosition; float angleToPlayer = Vector3.Angle(lookDirection, lookingPoint.forward); float normalizedAngle = ExtensionFunctions.To360Angle(angleToPlayer); if (normalizedAngle <= maxLookAngle) { return(normalizedAngle); } else { return(-1); } }
public void PlaceTreesOnPoints() { hasPlacedTrees = true; float maxValue = float.MinValue; for (int i = 0; i < treePoints.Length; i++) { if (treePoints[i].y > maxValue) { maxValue = treePoints[i].y; } } for (int i = 0; i < treePoints.Length; i++) { float normalizedPoint = ExtensionFunctions.Map(treePoints[i].y, 0, maxValue, 0, 1); trees[i] = TreesManager.instance.RequestTree(normalizedPoint); if (trees[i] != null) { trees[i].transform.position = treePoints[i] + _meshCenter; trees[i].SetActive(true); } } }
public int AddFirefly(bool destroyOnReachTarget, Vector3 spawnPoint, Transform target = null) { if (target == null) { target = GetRandomTransformPoint(); } if (ExtensionFunctions.IsVectorZero(spawnPoint)) { spawnPoint = GetRandomTransformPoint().position; } _currentIndex += 1; GameObject fireflyInstance = SpawnFirefly(spawnPoint); FloatyFollowTarget followTarget = fireflyInstance.GetComponent <FloatyFollowTarget>(); FireflyInformation fireflyInformation = new FireflyInformation { destroyOnReachTarget = destroyOnReachTarget, fireflyIndex = _currentIndex, fireflyInstance = followTarget }; followTarget.UpdateTarget(target); _fireflies.Add(fireflyInformation); return(_currentIndex); }
private void StopPlayerOnExtremeSlope() { if (Physics.Raycast(raycastPoint.position, Vector3.down, out _hit)) { float moveX = Input.GetAxis(Controls.HorizontalAxis); float moveZ = Input.GetAxis(Controls.VerticalAxis); Vector3 playerAxis = transform.forward; if (moveZ < 0) { playerAxis = -transform.forward; } else if (moveX > 0) { playerAxis = transform.right; } else if (moveX < 0) { playerAxis = -transform.right; } float angle = Vector3.Angle(_hit.normal, playerAxis); float normalizedAngle = ExtensionFunctions.To360Angle(angle); if (normalizedAngle - 90 > maxAngleAllowed) { _playerRB.velocity = Vector3.zero; } } }
private void SetSmokeBasedOnHealth() { float healthRatio = _healthSetter.GetCurrentHealth() / _healthSetter.maxHealthAmount; if (healthRatio > thresholdHealthRatio) { return; } if (_smokeParticles.Count == 0) { GameObject smokeInstance = Instantiate(droneDamageSmoke, smokeSpawnPoint.position, droneDamageSmoke.transform.rotation); smokeInstance.transform.SetParent(smokeSpawnPoint); _smokeParticles = smokeInstance.GetComponentsInChildren <ParticleSystem>().ToList(); } foreach (ParticleSystem particle in _smokeParticles) { float mappedEmissionRate = ExtensionFunctions.Map( healthRatio, thresholdHealthRatio, 0, minParticles, maxParticles ); ParticleSystem.EmissionModule emission = particle.emission; emission.rateOverTime = mappedEmissionRate; } }
public void UpdateHealth() { float currentHealthRatio = currentCarHealth / maxCarHealth; if (currentHealthRatio >= healthRatioToSpawnFire) { return; } if (vehicleFireParticleSystem.Count == 0) { GameObject vehicleFireInstance = Instantiate(vehicleFire, vehicleFireSpawnPoint.transform.position, vehicleFire.transform.rotation); vehicleFireInstance.transform.SetParent(gameObject.transform); vehicleFireParticleSystem.Add(vehicleFireInstance. transform.GetChild(0).GetComponent <ParticleSystem>()); vehicleFireParticleSystem.Add(vehicleFireInstance. transform.GetChild(1).GetComponent <ParticleSystem>()); } foreach (ParticleSystem item in vehicleFireParticleSystem) { float mappedEmission = ExtensionFunctions.Map(currentHealthRatio, healthRatioToSpawnFire, 0, minFireParticles, maxFireParticles); ParticleSystem.EmissionModule emission = item.emission; emission.rateOverTime = mappedEmission; } }
private Vector3 GetSpawningPoint() { Vector3 destination = referencePoint.position + referencePoint.forward * spawnBeforeDistance; RaycastHit hit; if (Physics.Linecast(referencePoint.position, destination, out hit)) { destination = referencePoint.position + referencePoint.forward * (hit.distance - 1); } if (Physics.Raycast(destination, Vector3.down, out hit)) { destination = hit.point; float angle = Vector3.Angle(hit.normal, transform.forward); float normalizedAngle = ExtensionFunctions.To360Angle(angle); if (normalizedAngle - 90 > cannonSlopeAllowed) { return(Vector3.zero); } else { return(destination); } } return(Vector3.zero); }
private void CheckAndPickUpCannon() { if (!_cannonSpawned) { return; } if (Input.GetKey(Controls.CannonSpawnKey) && _cannonInRange) { _currentCollectionTime -= Time.deltaTime; _displayImage.enabled = true; _displayImage.fillAmount = ExtensionFunctions.Map(_currentCollectionTime, 0, collectionTime, 0, 1); if (_currentCollectionTime <= 0) { _cannonInstance.SetActive(false); _cannonSpawned = false; _cannonInRange = false; ResetTimerImage(); } } else if (!Input.GetKey(Controls.CannonSpawnKey)) { ResetTimerImage(); } }
public void ReduceVelocity() { // Prevent player from slowing down/speeding up while speed is different. if (!ExtensionFunctions.FloatCompare(_velocityScaler, 1)) { return; } _velocityScaler = 1; if (_poseDuration > 0 && _boostDuration <= 0) { _velocityScaler = GameInfo.PlayerIncreasedVelocity; _boostDuration = GameInfo.PlayerBoostDuration; MainScreen.Instance.PlayerDashed(); } else { _velocityScaler = GameInfo.PlayerDamageVelocity; if (_playerGameObject.Position.Y < GameInfo.PlayerMinYPosition) { return; } _playerGameObject.Position -= new Vector2(0, GameInfo.PlayerKnockBack); MainScreen.Instance.PlayerCollided(); } }
private void ServerUpdate() { if (!isServer) { return; } _nextShootTick += Time.fixedDeltaTime; if (_nextShootTick / _currentShootRate >= 1) { ShootAtPlayer(); _nextShootTick = 0; _currentShootRate = useConstantRate ? fireRate : Random.Range(minFireRate, maxFireRate); } MoveSpaceship(); _screenWrapper.CheckObjectOutOfScreen(); Vector3 position = transform.position; float percentX = ExtensionFunctions.Map(position.x, _screenWrapper.LeftMostPoint, _screenWrapper.RightMostPoint, -1, 1); float percentY = ExtensionFunctions.Map(position.y, _screenWrapper.TopMostPoint, _screenWrapper.BottomMostPoint, 1, -1); _nextTick += Time.fixedDeltaTime; if (_nextTick / updateSendRate >= 1) { RpcLocalClientSpaceshipPositionFixer(percentX, percentY, _spaceshipRb.velocity, Time.time); _nextTick = 0; } }
private void SetAndLimitPitch() { var mouseY = Input.GetAxis(MouseY); _pitch += -mouseY * verticalSpeed * Time.deltaTime; if (_pitch < 0 || _pitch > 360) { _pitch = ExtensionFunctions.To360Angle(_pitch); } if (_pitch > minCameraAngle && _pitch < maxCameraAngle) { var diffToMinAngle = Mathf.Abs(minCameraAngle - _pitch); var diffToMaxAngle = Mathf.Abs(maxCameraAngle - _pitch); if (diffToMinAngle < diffToMaxAngle) { _pitch = minCameraAngle; } else { _pitch = maxCameraAngle; } } }
private void RotateVertically() { float mouseY = Input.GetAxis(Controls.MouseY); _pitch += -mouseY * verticalSpeed * Time.deltaTime; if (_pitch < 0 || _pitch > 360) { _pitch = ExtensionFunctions.To360Angle(_pitch); } if (_pitch > minCameraAngle && _pitch < maxCameraAngle) { float diffToMinAngle = Mathf.Abs(minCameraAngle - _pitch); float diffToMaxAngle = Mathf.Abs(maxCameraAngle - _pitch); if (diffToMinAngle < diffToMaxAngle) { _pitch = minCameraAngle; } else { _pitch = maxCameraAngle; } } weapons.localRotation = Quaternion.Euler(_pitch, 0, 0); }
public static float CheckTargetInsideFOV(Transform target, float minimumDetectionDistance, float maxLookAngle, Transform lookingPoint, bool checkPlayerInBuildingStatus = true) { if (target == null) { return(-1); } var distanceToPlayer = Vector3.Distance(target.position, lookingPoint.position); if (distanceToPlayer > minimumDetectionDistance) { return(-1); } if (checkPlayerInBuildingStatus && GlobalData.playerInBuilding) { return(-1); } var modifiedPlayerPosition = new Vector3(target.position.x, 0, target.position.z); var modifiedLookingPosition = new Vector3(lookingPoint.position.x, 0, lookingPoint.position.z); var lookDirection = modifiedPlayerPosition - modifiedLookingPosition; var angleToPlayer = Vector3.Angle(lookDirection, lookingPoint.forward); var normalizedAngle = ExtensionFunctions.To360Angle(angleToPlayer); if (normalizedAngle <= maxLookAngle) { return(normalizedAngle); } return(-1); }
public void PlaceTreesOnPoints() { hasPlacedTrees = true; var maxValue = float.MinValue; for (var i = 0; i < _treePoints.Length; i++) { if (_treePoints[i].y > maxValue) { maxValue = _treePoints[i].y; } } for (var i = 0; i < _treePoints.Length; i++) { if (_treePoints[i] == Vector3.zero) { Debug.Log("Tree At Zero"); } var normalizedPoint = ExtensionFunctions.Map(_treePoints[i].y, 0, maxValue, 0, 1); _trees[i] = TreesManager.instance.RequestTree(normalizedPoint); if (_trees[i] != null) { _trees[i].transform.position = _treePoints[i] + _meshCenter; if (_treeSettings.useRandomTreeRotation) { _trees[i].transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0); } _trees[i].SetActive(true); } } }
private void LocalClientUpdate() { if (isServer) { return; } float timestamp = Time.time; if (isPredictionEnabled) { _screenWrapper.CheckObjectOutOfScreen(); Vector2 position = transform.position; _predictedPackages.Add(new PositionTimestampReceivePackage { percentX = ExtensionFunctions.Map(position.x, _screenWrapper.LeftMostPoint, _screenWrapper.RightMostPoint, -1, 1), percentY = ExtensionFunctions.Map(position.y, _screenWrapper.TopMostPoint, _screenWrapper.BottomMostPoint, 1, -1), timestamp = timestamp }); } }
private void UpdateCameraShake(float deltaTime) { _shakeOffset.X = ExtensionFunctions.RandomInRange(-_shakeMultiplier, _shakeMultiplier); _shakeOffset.Y = ExtensionFunctions.RandomInRange(-_shakeMultiplier, _shakeMultiplier); _camera.Position = _cameraInitialPosition + _shakeOffset; }
private void ShootChargedBullet() { if (_chargedShotBullet == null) { return; } _playerChargedShotShootingPosition.RemoveChild(_chargedShotBullet); _playerBulletHolder.AddChild(_chargedShotBullet); float maxDamage = _chargedShotBullet.GetBulletDamage() + _currentDamageDiff; float mappedDamage = ExtensionFunctions.Map(_chargeWeaponCurrentScale, 0, chargeGunMaxScaleAmount, 0, maxDamage); _chargedShotBullet.SetBulletDamage(mappedDamage); _chargedShotBullet.SetGlobalPosition(_playerChargedShotShootingPosition.GetGlobalPosition()); _chargedShotBullet.SetGlobalScale(Vector2.One * _chargeWeaponCurrentScale); float currentRotation = _playerRoot.GetRotation(); _chargedShotBullet.SetGlobalRotation(currentRotation); _chargedShotBullet.SetAsDynamicBullet(); _chargedShotBullet.SetMode(RigidBody2D.ModeEnum.Rigid); float xVelocity = Mathf.Cos(currentRotation); float yVelocity = Mathf.Sin(currentRotation); _chargedShotBullet.LaunchBullet(new Vector2(xVelocity, yVelocity).Normalized()); _chargedShotBullet = null; bulletShot?.Invoke(_currentWeaponType); }
private void LateUpdate() { float xPos = ExtensionFunctions.GetClosestMultiple(groundTrackingPoint.position.x); float zPos = ExtensionFunctions.GetClosestMultiple(groundTrackingPoint.position.z); objectSnappingPoint.transform.position = new Vector3(xPos, 0, zPos); }
private void FloatingScaleChange(float delta) { float scaleMultiplier = Mathf.Sin(scaleChangeFrequency * _playerTime); float scaleAmount = ExtensionFunctions.Map(scaleMultiplier, -1, 1, minScaleAmount, maxScaleAmount); _targetScale = Vector2.One * scaleAmount; }
public void Update(float deltaTime) { float ratio = _currentValue / _maxValue; _barHeight = ExtensionFunctions.Map(ratio, 0, 1, 0, _maxTopBarHeight); _topBar.SetSize((int)_topBar.ScaledWidth, (int)_barHeight); }
public override void _Process(float delta) { float currentYPosition = GetGlobalPosition().y; float clampedYPosition = Mathf.Clamp(currentYPosition, minYPosition, maxYPosition); SetSelfModulate(_currentColor.LinearInterpolate(endColor, ExtensionFunctions.Map(clampedYPosition, minYPosition, maxYPosition, 0, 1))); }
private void HandleInput(float deltaTime) { int speedFactor = 1; if (_playerController.DidPlayerPressDash && _dashCooldown <= 0 && ExtensionFunctions.FloatCompare(1, _velocityScaler) && _consecutivePoseCount < GameInfo.MaxPoseCount) { if (_currentPose) { GameObject.Sprite.UpdateTexture(_pose1); _currentPose = !_currentPose; } else { GameObject.Sprite.UpdateTexture(_pose2); _currentPose = !_currentPose; } _dashDuration = GameInfo.PlayerDashDuration; _dashDirection = _playerController.DashDirection; _poseDuration = GameInfo.PlayerPoseDuration; _consecutivePoseCount += 1; } if (_dashDuration > 0) { if (_velocityScaler == 1) { speedFactor = 3; } _playerGameObject.Position += _dashDirection * GameInfo.PlayerDashVelocity * deltaTime; } if (_playerController.State == PlayerController.ControllerState.Right) { _playerGameObject.Position += GameInfo.HorizontalVelocity * deltaTime * _velocityScaler * speedFactor; } else if (_playerController.State == PlayerController.ControllerState.Left) { _playerGameObject.Position -= GameInfo.HorizontalVelocity * deltaTime * _velocityScaler * speedFactor; } else if (_playerController.State == PlayerController.ControllerState.Up) { if (_playerGameObject.Velocity.Y < GameInfo.PlayerMinYVelocity) { return; } _playerGameObject.Position -= GameInfo.VerticalVelocity * deltaTime * _velocityScaler * speedFactor; _playerGameObject.Acceleration -= GameInfo.AccelerationChangeRate * deltaTime; } else if (_playerController.State == PlayerController.ControllerState.Down) { _playerGameObject.Position += GameInfo.VerticalVelocity * deltaTime * _velocityScaler * speedFactor; _playerGameObject.Acceleration += GameInfo.AccelerationChangeRate * deltaTime; } }
/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { float maxVelocity = _creatureAgent.speed * _creatureAgent.speed; float currentVelocity = _creatureAgent.velocity.sqrMagnitude; float movementSpeed = ExtensionFunctions.Map(currentVelocity, 0, maxVelocity, 0, 1); _creatureAnimator.SetFloat(AnimatorMovement, movementSpeed); }
private void Update() { timeText.text = $"Time : {ExtensionFunctions.Format2DecimalPlace(currentTime)} s"; killsText.text = $"Kills : {currentKills}"; if (countScore) { currentTime += Time.deltaTime; } }
private void Update() { var maxVelocity = _droidAgent.speed * _droidAgent.speed; var currentVelocity = _droidAgent.velocity.sqrMagnitude; var movementSpeed = ExtensionFunctions.Map(currentVelocity, 0, maxVelocity, 0, 1); droidAnimator.SetFloat(AnimatorMovement, movementSpeed); }
/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { if (!startScoring) { return; } currentScore += (scoreIncreaseRate * Time.deltaTime); uiScoreText.text = $"Score: {ExtensionFunctions.Format2DecimalPlace(currentScore)}"; }
public void HealHealth(int amt) { currentHealth += amt; greenBar.localScale = new Vector3(Mathf.Clamp(ExtensionFunctions.Map((float)currentHealth, 0f, (float)maxHealth, 0f, 1f), 0f, 1f), greenBar.localScale.y, greenBar.localScale.z); greenBarX = greenBar.localScale.x + ExtensionFunctions.Map(amt, 0, maxHealth, 0, 1); StopCoroutine(LerpGreenBar()); if (gameObject.activeSelf) { StartCoroutine(LerpGreenBar()); } }
private void Initialize() { if (_initialized) { return; } _initialized = true; _fadeImage = GetComponent <Image>(); _currentAlpha = ExtensionFunctions.Map(_fadeImage.color.a, 0, 1, 0, 255); }
/// <summary> /// Start is called on the frame when a script is enabled just before /// any of the Update methods is called the first time. /// </summary> void Start() { float currentScore = 0; if (PlayerPrefs.HasKey(PlayerPrefsVariables.PlayerScore)) { currentScore = PlayerPrefs.GetFloat(PlayerPrefsVariables.PlayerScore); } scoreText.text = $"Highest Score: {ExtensionFunctions.Format2DecimalPlace(currentScore)}"; }