private void PeakJump() { nextPosition = transform.position; nextPosition.y = jumpHeight; transform.position = nextPosition; State = BounceState.Airborne; }
private void Ground() { nextPosition = transform.position; nextPosition.y = 0f; transform.position = nextPosition; State = BounceState.Grounded; }
private void Update() { if (Input.GetMouseButtonDown(0) && _bounceState != BounceState.Up) { if (isBusy == false) { _bounceState = BounceState.Up; } } if (_bounceState != BounceState.None && isOkToBounce) { if (coinCount > 0) { Bounce(); } else { if (isFinishedBounce) { _anim.enabled = false; SetSprite(_emptyBlock); isFinishedBounce = false; } } } }
private void Bounce() { Vector3 currentPos = transform.position; if (_bounceState == BounceState.Up) { if (currentPos.y <= _posBeforeBounce.y + _bounceYDist) { transform.Translate(_bounceVelocity * Vector2.up * Time.fixedDeltaTime); } else { _bounceState = BounceState.Down; } } else if (_bounceState == BounceState.Down) { if (currentPos.y >= _posBeforeBounce.y) { transform.Translate(_bounceVelocity * Vector2.down * Time.fixedDeltaTime); } else { _bounceState = BounceState.None; transform.position = _posBeforeBounce; GivePrize(); } } }
public void TriggerBounce() { if (isBusy == false) { _bounceState = BounceState.Up; } }
public void Start() { State = BounceState.Grounded; GameState.Instance.OnGameEnd.AddListener(OnGameEnd); if (runOnStart) { Run(); } }
private void OnTriggerEnter2D(Collider2D other) { Debug.Log("Collision Detected...."); if (other.transform.tag == "Player") { Debug.Log("Player"); _bounceState = BounceState.Up; } }
void OnInteraction(SMBPlayer player) { if (_bounceState == BounceState.None && !_isDestroyed) { DestroyBlock(player); _posBeforeBounce = transform.position; _bounceState = BounceState.Up; } }
private void Bounce() { isBusy = true; currentPosition = transform.position; if (coinCount == 1) { _anim.enabled = false; SetSprite(_emptyBlock); isFinishedBounce = false; } if (_bounceState == BounceState.Up) { if (currentPosition.y <= _posBeforeBounce.y + _bounceYDist) { transform.Translate(_bounceVelocity * Vector2.up * Time.fixedDeltaTime); } else { _bounceState = BounceState.Down; PowerUpType(option); } } else if (_bounceState == BounceState.Down) { if (currentPosition.y >= _posBeforeBounce.y) { transform.Translate(_bounceVelocity * Vector2.down * Time.fixedDeltaTime); } else { if (coinCount == 1) { isOkToBounce = false; } //Rigidbody2D r2d = GetComponent<Rigidbody2D>(); //r2d.isKinematic = true; _bounceState = BounceState.None; transform.position = _posBeforeBounce; } } }
// bounce up and down and rotate on z axis public void Shake(ShakeArgument argument) { if (_bounceState == BounceState.Static || _bounceState == BounceState.ToStatic) { _shakeEndTime = Time.time; } // time related calculations _shakeArgument = argument; _shakeEndTime = Time.time + Random.Range( argument.minDuration, argument.maxDuration); _bounceState = BounceState.ToBouncing; // race condition vs Update solution _rotateState = RotateState.ToRotating; // position calculations _bounceOffset = new Vector3(0, argument.bounceMax / 4); // todo: improve offset _sqrBounceSpeed = argument.bounceSpeed * argument.bounceSpeed; // rotation calculations _sqrRotationSpeed = argument.rotationSpeed * argument.rotationSpeed; halfAngleOffset = argument.rotationMax / 2; }
public void Fall() { step = 0f; State = BounceState.Falling; }
public void Jump() { step = 0f; State = BounceState.Jumping; }
void Update() { // optimizable float sampleY = _shakeArgument.bounceMax * Mathf.PerlinNoise(0, Time.time * _shakeArgument.bounceSpeed); Vector3 bounceOffset = (sampleY * Vector3.up) - _bounceOffset; Vector3 cameraRestingPosition = target.position + cameraOffset; Vector3 cameraRelativeTargetPosition = cameraRestingPosition + bounceOffset; switch (_bounceState) { case BounceState.Static: localTransform.position = cameraRestingPosition; break; case BounceState.ToBouncing: localTransform.position = Vector3.MoveTowards( localTransform.position, cameraRelativeTargetPosition, transitionSpeed); if (_sqrBounceSpeed > Vector3.SqrMagnitude(localTransform.position - cameraRelativeTargetPosition)) { _bounceState = BounceState.Bouncing; } break; case BounceState.Bouncing: localTransform.position = cameraRelativeTargetPosition; if (Time.time > _shakeEndTime) { _bounceState = BounceState.ToStatic; } break; case BounceState.ToStatic: localTransform.position = Vector3.MoveTowards(localTransform.position, cameraRestingPosition, transitionSpeed); if (_sqrBounceSpeed > Vector3.SqrMagnitude(localTransform.position - cameraRestingPosition)) { _bounceState = BounceState.Static; } break; default: throw new ArgumentOutOfRangeException(); } float sampleAngle = _shakeArgument.rotationMax * Mathf.PerlinNoise(Time.time * _shakeArgument.rotationSpeed, 0) - halfAngleOffset; Quaternion targetRotation = Quaternion.AngleAxis(sampleAngle, localTransform.forward); switch (_rotateState) { case RotateState.Static: break; case RotateState.ToRotating: localTransform.rotation = Quaternion.RotateTowards( localTransform.rotation, targetRotation, _shakeArgument.rotationSpeed); if (_sqrRotationSpeed > Mathf.Abs( localTransform.rotation.eulerAngles.z - targetRotation.eulerAngles.z)) { _rotateState = RotateState.Rotating; } break; case RotateState.Rotating: localTransform.rotation = targetRotation; if (Time.time > _shakeEndTime) { _rotateState = RotateState.ToStatic; } break; case RotateState.ToStatic: localTransform.rotation = Quaternion.RotateTowards( localTransform.rotation, targetRotation, _shakeArgument.rotationSpeed); if (_sqrRotationSpeed > Mathf.Abs(localTransform.rotation.eulerAngles.z)) { localTransform.rotation = Quaternion.identity; _rotateState = RotateState.Static; } break; default: throw new ArgumentOutOfRangeException(); } }
void Start() { _posBeforeBounce = transform.position; _bounceState = BounceState.Up; }