// Update is called once per frame protected void Update() { ProcessSensoInput(); //Check Activity Timeouts and if Player Present if (_totalForce > playerPresenceForceThreshold) { lastActivity = Time.time; } //else { // //if noone is there, reset the center of gravity // _cog = _sensoCenter; //} _playerPresent = Time.time - lastActivity < activityTimeout; if (_playerPresent != _playerPresentLast) { OnPlayerPresenceChanged?.Invoke(_playerPresent); } //Check for movement patterns if (_totalForce < jumpForceThreshold) { if (!jump && Mathf.Abs(_jumpTimer) < playerPresenceForceThreshold) { OnJumped?.Invoke(_cog.x, _cog.y); if (logging) { Debug.Log("Jumped"); } _jumpTimer = 0f; jump = true; } else { _jumpTimer += Time.deltaTime; if (_jumpTimer > maxJumpTime & jump) { jump = false; if (logging) { Debug.Log("Jump Cancelled"); } OnJumpCancelled?.Invoke(); } } } else { if (jump) { OnJumpLanded?.Invoke(_cog.x, _cog.y); if (logging) { Debug.Log("Jump landed"); } } jump = false; _jumpTimer = 0f; } }
public bool Jump() { if (!IsGrounded) { return(false); } moveVelocity.y = jumpHeight; OnJumped.SafeInvoke(); return(true); }
private void fuJumping(float jumpSpeed, bool doForceJump = false) { if (hasControl) { //still not entirely sure, why this gets called twice per jump //pressed - has to do with how its calculated if (holdingJump && (isOnGround || doForceJump)) { rb.velocity = new Vector2(rb.velocity.x, jumpSpeed); OnJumped?.Invoke(); } //TODO Why is the player floaty when gravityScale = 1 ??? //I wanna change it to 1 so that the launches-away from the //enemy are good. //Alternatively, I could increase the launch-vector's y //component. } }
private void HandleInput() { if (IsGrounded) { inputVelocity.y = 0; } normalizedHorizontalSpeed = Input.GetAxis(HorizontalAxisName); var vertiacalAxis = Input.GetAxis(VerticalAxisName); // We can only jump whilst grounded. if (IsGrounded && Input.GetButtonDown(JumpButtonName)) { inputVelocity.y = Mathf.Sqrt(2f * JumpHeight * -Gravity); OnJumped?.Invoke(); } // Apply horizontal speed smoothing it. var smoothedMovementFactor = IsGrounded ? GroundDamping : InAirDamping; // how fast do we change direction? inputVelocity.x = Mathf.Lerp(inputVelocity.x, normalizedHorizontalSpeed * RunSpeed, Time.deltaTime * smoothedMovementFactor); // Apply gravity before moving. inputVelocity.y += Gravity * Time.deltaTime; // If holding down bump up our movement amount and turn off one way platform detection for a frame. // This lets us jump down through one way platforms. if (IsGrounded && vertiacalAxis < 0) { inputVelocity.y *= 3f; ignoreOneWayPlatformsThisFrame = true; } Move(inputVelocity * Time.deltaTime); // Grab our current velocity to use as a base for all calculations. inputVelocity = Velocity; }
// Update is called once per frame void LateUpdate() { //1. UPDATE PLATE STATE (including simulation with keys) _plates = (Plate[])Hardware.Plates.Clone(); Direction[] dirs = (Direction[])System.Enum.GetValues(typeof(Direction)); foreach (Direction dir in dirs) { KeyCode key = DirectionToKey(dir); if (Input.GetKeyDown(key)) { //Debug.Log("step " + dir); _plates[(int)dir] = GetSimulatedPlate(dir, true, true); } else if (Input.GetKeyUp(key)) { //Debug.Log("release " + dir); _plates[(int)dir] = GetSimulatedPlate(dir, false, true); } else if (Input.GetKey(key)) { //Debug.Log("down " + dir); _plates[(int)dir] = GetSimulatedPlate(dir, true, false); } } //Calculate the center of gravity and the cumulated force on all plates Vector2 cog = new Vector2(); float weight = 0f; for (int i = 0; i < _plates.Length; i++) { cog += _plates[i].f * (new Vector2(_plates[i].x, _plates[i].y)); weight += _plates[i].f; } if (Mathf.Abs(weight) > 0.01f) { _cog = 1 / weight * cog; } else { _cog = _sensoCenter; } _totalForce = weight; //Check Activity Timeouts and if Player Present if (_totalForce > 0.01f) { lastActivity = Time.time; } playerPresent = Time.time - lastActivity < activityTimeout; //Check for movement patterns if (_totalForce < jumpForceThreshold) { if (!jump && Mathf.Abs(_jumpTimer) < 0.01f) { OnJumped?.Invoke(_cog.x, _cog.y); Debug.Log("Jumped"); _jumpTimer = 0f; jump = true; } else { _jumpTimer += Time.deltaTime; if (_jumpTimer > maxJumpTime & jump) { jump = false; Debug.Log("Jump Cancelled"); OnJumpCancelled?.Invoke(); } } } else { if (jump) { OnJumpLanded?.Invoke(_cog.x, _cog.y); Debug.Log("Jump landed"); } jump = false; _jumpTimer = 0f; } }
internal void on_OnJumped() => OnJumped?.Invoke();
public void Jump() { OnJumped?.Invoke(this); OnCanceledCling?.Invoke(this); _rb.isKinematic = true; }