IEnumerator Jump() { var targetPos = DetectExecutedJump(); var gravity = JumpVelocityCalculator.GetGravity2D(_rb); var jumpVel = JumpVelocityCalculator.Calculate(_cachedTransform.position, targetPos, gravity, _jumpMaxHeight, true); _rb.velocity = jumpVel.velocity; yield return(new WaitForSeconds(jumpVel.simulatedTime)); }
IEnumerator Jump() { var isTargetLeft = _target.position.x < transform.position.x; var jumpX = transform.position.x + 1.325f * (isTargetLeft ? -1 : 1); var targetPos = new Vector3(jumpX, transform.position.y, transform.position.z); var gravity = JumpVelocityCalculator.GetGravity2D(_rb); var jumpVel = JumpVelocityCalculator.Calculate(transform.position, targetPos, gravity, _jumpMaxHeight, true); _rb.velocity = jumpVel.velocity; InstantiateTheDirectedDust(); yield return(new WaitForSeconds(jumpVel.simulatedTime)); }
IEnumerator Jump() { // var targetPos = new Vector3(_boundary.transform.position.x, _executedPoint.position.y, 0); var targetPos = DetectExecutedJump(); var storedGravityScale = _rb.gravityScale; _rb.gravityScale *= 1.125f; var gravity = JumpVelocityCalculator.GetGravity2D(_rb); var jumpVel = JumpVelocityCalculator.Calculate(_cachedTransform.position, targetPos, gravity, _jumpMaxHeight, true); _rb.velocity = jumpVel.velocity; yield return(new WaitForSeconds(jumpVel.simulatedTime)); _rb.gravityScale = storedGravityScale; }
IEnumerator JumpForDeath(float distance, float height, float deltaGravityScale) { _rb.constraints = RigidbodyConstraints2D.FreezeRotation; _rb.gravityScale *= deltaGravityScale; var spriteTransform = bodySpriteRenderer.transform; var positionAtDeath = new Vector3(spriteTransform.position.x + distance, spriteTransform.position.y, spriteTransform.position.z); var gravity = JumpVelocityCalculator.GetGravity2D(_rb); var jumpVel = JumpVelocityCalculator.Calculate(spriteTransform.position, positionAtDeath, Vector3.zero, positionAtDeath, gravity, height, true); var _currentVel = jumpVel.velocity; _rb.velocity = _currentVel; yield return(new WaitForSeconds(jumpVel.simulatedTime)); _rb.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation; }
IEnumerator Lauching(Vector3 targetPosition, Vector3 deltaDistance, Vector3 stopPosition, System.Action reachedTargetAction = null) { var gravity = JumpVelocityCalculator.GetGravity2D(_rb); var jumpVel = JumpVelocityCalculator.Calculate(transform.position, targetPosition, deltaDistance, stopPosition, gravity, height, true); _currentVel = jumpVel.velocity; _rb.velocity = _currentVel; yield return(new WaitForSeconds(jumpVel.simulatedTime)); if (reachedTargetAction != null) { reachedTargetAction(); } Destroy(gameObject); }
IEnumerator Jump() { FlipX(); var isTargetLeft = _target.position.x < transform.position.x; var bounds = _boundary.bounds; var halfX = bounds.min.x + (bounds.max.x - bounds.min.x) / 2f; var targetPos = new Vector3(halfX, transform.position.y, transform.position.z); var gravity = JumpVelocityCalculator.GetGravity2D(_rb); var jumpVel = JumpVelocityCalculator.Calculate(transform.position, targetPos, gravity, _jumpMaxHeight, true); _rb.velocity = jumpVel.velocity; _anim.Play(_jump.name); InstantiateTheDirectedDust(); InstantiateTheDust(.75f); yield return(new WaitForSeconds(jumpVel.simulatedTime)); }