private void ApplyGravity() { if (!IsGrounded) { CharacterRigidbody.AddForce(Vector3.up * -9.8f, ForceMode.Acceleration); } }
void Start() { _collider = new CharacterCollider(GetComponentInChildren <Collider2D>(), groundLayer); _stateMachine = new CharacterStateMachine(this); _input = new KeyboardCharacterInput(); _animator = GetComponentInChildren <Animator>(); _spriteRenderer = GetComponentInChildren <SpriteRenderer>(); _gravity = (2 * jumpHeight) / Mathf.Pow(timeToApex, 2); _jumpVelocity = Mathf.Sqrt(2 * _gravity * jumpHeight); _rigidbody = new CharacterRigidbody(_gravity, transform, _collider); }
private void PhysicsMove() { desiredSpeed = MoveSpeed * InputVector.magnitude; if (desiredSpeed < currentSpeed) { deceleration = (desiredSpeed < 0.3f) ? deceleration = 2.0f : deceleration = 0.8f; } else { deceleration = 1.0f; } currentSpeed = Mathf.Lerp(currentSpeed, desiredSpeed, acceleration * deceleration * Time.deltaTime); Vector3 v = Vector3.zero; DesiredVelocity = Vector3.SmoothDamp(DesiredVelocity, DesiredDirection, ref v, rotationSpeed); CharacterRigidbody.MovePosition(transform.position + DesiredVelocity * currentSpeed * Time.deltaTime); }
protected virtual IEnumerator HurtAnimation(GameObject attacker) { CharacterRigidbody.AddForce((transform.position - attacker.transform.position) * 10, ForceMode2D.Impulse); return(null); }
public void Jump(float force) { CharacterRigidbody.AddForce(force * Vector3.up, ForceMode.VelocityChange); }