void ThrownMovement() { floorAttachingMovement.MoveSideWays(throwMomentum); if (throwMomentum == 0 && floorAttachingMovement.isGrounded) { state = ThrowableState.Recovering; StartRecovery(); return; } if (throwMomentum < 0.5f && throwMomentum > -0.5f) { throwMomentum = 0; } if (floorAttachingMovement.isGrounded) { bounceDown(); } if (floorAttachingMovement.topAngle.detect) { bounceUp(); } if (floorAttachingMovement.isBumping) { bounceSide(); } directionFloatX = Mathf.Sign(throwMomentum); ChangeDirection(); }
void StartRecovery() { disableAttackBoxes(); state = ThrowableState.Recovering; RecoveryRoutine = Recovering(); StartCoroutine(RecoveryRoutine); }
public void Drop() { m_currentObjectState = ThrowableState.Inactive; m_rb.isKinematic = false; m_objectToFollow = null; m_pickable = true; m_rb.velocity = Vector2.zero; }
//************************// // Public Functions // //************************// public void PickUp(Transform _target, float _speed, float _targetReachedTolerance) { m_rb.velocity = Vector2.zero; m_objectToFollow = _target; m_currentObjectState = ThrowableState.TravellingToPlayer; m_speed = _speed; m_targetReachedTolerance = _targetReachedTolerance; m_rb.isKinematic = true; }
public override void OnPlayerTouch(PlayerScript player) { if (state == ThrowableState.Free || state == ThrowableState.Recovering) { player.HoldObject(this); state = ThrowableState.Carried; carrier = player; verticalCalulation = 0; } }
private void SetInactive() { m_okb.IsLethal(false); m_rb.velocity = Vector2.zero; m_rb.gravityScale = 1f; m_currentObjectState = ThrowableState.Inactive; //GetComponent<SpriteRenderer>().color = Color.blue; m_pickable = true; ResetRotation(); SubstractDurability(); }
public void getThrown(float DirectionX) { transform.parent = null; carrier = null; if (RecoveryRoutine != null) { StopCoroutine(RecoveryRoutine); } state = ThrowableState.Thrown; enableAttackBoxes(); throwMomentum = DirectionX * throwForce; }
public void Throw(Vector2 _velocity, bool _isLethal, float _customSpeedMultiplier = -1, bool _pickableInAir = false) // nur ein parameter { if (_customSpeedMultiplier < 0) { _customSpeedMultiplier = m_speedMultiplier; } m_rb.velocity = _velocity * _customSpeedMultiplier; m_rb.gravityScale = 1 * Mathf.Pow(_customSpeedMultiplier, 2); m_currentObjectState = ThrowableState.Thrown; m_rb.isKinematic = false; m_hitGround = false; m_pickable = _pickableInAir; m_okb.IsLethal(_isLethal); AdjustSprite(_velocity); }
// Update is called once per frame void FixedUpdate() { switch (currentObjectState) { case ThrowableState.TravellingToPlayer: { CorrectRotation(180); Vector2 objectVelocity = (m_objectToFollow.transform.position - transform.position).normalized * m_speed; m_rb.velocity = objectVelocity; if (Vector2.Distance(transform.position, m_objectToFollow.transform.position) < m_targetReachedTolerance) { m_currentObjectState = ThrowableState.PickedUp; } break; } case ThrowableState.PickedUp: { m_rb.MovePosition(m_objectToFollow.GetComponent <Rigidbody2D>().position); break; } case ThrowableState.Inactive: { if (m_actor.contacts.any) { m_rb.velocity = Vector2.zero; //könnte das object dadurch an der decke kleben? if (m_hitGround == false) //facotored den drop nicht mit ein / schlimm? { SubstractDurability(); m_hitGround = true; } } break; } case ThrowableState.Thrown: { CorrectRotation(); //GetComponent<SpriteRenderer>().color = Color.yellow; if (m_actor.contacts.any) { SetInactive(); //abbprallen bei den leben mit einberechnen } break; } } }
IEnumerator Recovering() { yield return(new WaitForSeconds(recoveryTime)); state = ThrowableState.Free; }