Gradual jump and started orb events
This commit is contained in:
parent
e874c23647
commit
b4e11ac33f
11 changed files with 1035 additions and 99 deletions
|
@ -6,17 +6,20 @@ using UnityEngine.Serialization;
|
|||
|
||||
public class PlayerController : MonoBehaviour {
|
||||
|
||||
[Header("Stats")]
|
||||
[SerializeField] float speed = 50f;
|
||||
[SerializeField, Range(0f, .5f)] float acceleration = .1f;
|
||||
[SerializeField, Range(0f, .5f)] float flipSmooth = .1f;
|
||||
[SerializeField] float jumpForce = 10f;
|
||||
[SerializeField, Range(0f, 1f)] float gradualJumpMultiplier = .5f;
|
||||
|
||||
Vector2 _input;
|
||||
float _xVelocity, _flipVelocity;
|
||||
int _facingDirection = 1;
|
||||
bool _cancelJump;
|
||||
Rigidbody2D _rb2d;
|
||||
|
||||
[Space]
|
||||
[Header("Jump Management")]
|
||||
[SerializeField] LayerMask groundMask;
|
||||
[SerializeField, Range(0f, 1f)] float feetHeight;
|
||||
[SerializeField, Range(0f, 2f)] float feetWidth;
|
||||
|
@ -40,13 +43,16 @@ public class PlayerController : MonoBehaviour {
|
|||
_ => _facingDirection
|
||||
};
|
||||
|
||||
transform.localScale =
|
||||
new Vector3(Mathf.SmoothDamp(transform.localScale.x, _facingDirection, ref _flipVelocity, flipSmooth),
|
||||
transform.localScale.y, transform.localScale.z);
|
||||
Vector3 localScale = transform.localScale;
|
||||
localScale = new Vector3(Mathf.SmoothDamp(localScale.x, _facingDirection, ref _flipVelocity, flipSmooth),
|
||||
localScale.y, localScale.z);
|
||||
transform.localScale = localScale;
|
||||
|
||||
_isGrounded = Physics2D.OverlapBox(feetPos.position, new Vector2(feetWidth, feetHeight), 0f, groundMask);
|
||||
if (_isGrounded && _rb2d.velocity.y <= 0f) _coyoteTime = coyoteTime;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space)) _jumpBuffer = jumpBuffer;
|
||||
if (Input.GetKeyUp(KeyCode.Space)) _cancelJump = true;
|
||||
|
||||
_jumpBuffer -= Time.deltaTime;
|
||||
_coyoteTime -= Time.deltaTime;
|
||||
|
@ -60,6 +66,11 @@ public class PlayerController : MonoBehaviour {
|
|||
_rb2d.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
|
||||
_coyoteTime = _jumpBuffer = 0f;
|
||||
}
|
||||
|
||||
if (_cancelJump) {
|
||||
if(_rb2d.velocity.y > 0f) _rb2d.velocity = new Vector2(_rb2d.velocity.x, _rb2d.velocity.y * gradualJumpMultiplier);
|
||||
_cancelJump = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue