dash is working better!

This commit is contained in:
allylikesfrogs 2023-05-03 11:53:37 -07:00
parent 6fda5e48b5
commit f7d45185fa
3 changed files with 12072 additions and 265 deletions

File diff suppressed because it is too large Load Diff

View File

@ -20,12 +20,12 @@ public class PlayerBehavior : MonoBehaviour
[Header("Clarinet:")]
bool unlockedClarinet;
[SerializeField] private float dashMult = 2;
[SerializeField] private float maxDashTime = 5.0f;
[SerializeField] private float maxDashTime = 2.0f;
[SerializeField] private float dashStopSpeed = 0.01f;
private float currentDashTime;
public bool isDash = false;
public Vector2 moveDirection;
public float dashDistance = 5;
public Vector3 moveDirection;
public float dashDistance = 0.1f;
[Header("Grappling:")]
[SerializeField] public Tutorial_GrapplingGun grapplingGun;
@ -104,17 +104,17 @@ public class PlayerBehavior : MonoBehaviour
currentDashTime = 0.0f;
playerInput.DeactivateInput();
}
if (!playerController.IsGrounded() && (currentDashTime < maxDashTime))
if (!playerController.IsGrounded() && (currentDashTime < maxDashTime) && isDash)
{
if(forward == 1)
{
moveDirection = transform.right * dashDistance;
moveDirection = new Vector3(1f,-1f,0f) * dashDistance;
}
else
{
moveDirection = -(transform.right) * dashDistance;
moveDirection = new Vector3(-1f,-1f,0f) * dashDistance;
}
//_rb.AddForce(dashSpeed, ForceMode2D.Force);
transform.position = transform.position + moveDirection;
currentDashTime += dashStopSpeed;
print("cdt " + currentDashTime);
}

View File

@ -110,240 +110,224 @@ public class PlayerMovement : MonoBehaviour
private void Update()
{
isDashing = playerBehavior.isDash;
if(isDashing)
unlockedTrumpet = stateController.unlockedTrumpet;
#region TIMERS
LastOnGroundTime -= Time.deltaTime;
LastOnWallTime -= Time.deltaTime;
LastOnWallRightTime -= Time.deltaTime;
LastOnWallLeftTime -= Time.deltaTime;
LastPressedJumpTime -= Time.deltaTime;
#endregion
#region INPUT HANDLER
if (_moveInput.x != 0)
CheckDirectionToFace(_moveInput.x > 0);
#endregion
// if (!IsJumping)
// {
// print("not jumping");
// }
// else
// {
// print("jumping, " + RB.velocity.y);
// }
#region COLLISION CHECKS
if (!IsJumping)
{
FreezeControl();
}
else{
if(isFrozen)
//Ground Check
if (IsGrounded()) //checks if set box overlaps with ground
{
Data.gravityStrength = tempGrav;
Data.fallGravityMult = tempFall;
isFrozen = false;
}
unlockedTrumpet = stateController.unlockedTrumpet;
#region TIMERS
LastOnGroundTime -= Time.deltaTime;
LastOnWallTime -= Time.deltaTime;
LastOnWallRightTime -= Time.deltaTime;
LastOnWallLeftTime -= Time.deltaTime;
LastPressedJumpTime -= Time.deltaTime;
#endregion
#region INPUT HANDLER
if (_moveInput.x != 0)
CheckDirectionToFace(_moveInput.x > 0);
#endregion
// if (!IsJumping)
// {
// print("not jumping");
// }
// else
// {
// print("jumping, " + RB.velocity.y);
// }
#region COLLISION CHECKS
if (!IsJumping)
{
//Ground Check
if (IsGrounded()) //checks if set box overlaps with ground
{
LastOnGroundTime = Data.coyoteTime; //if so sets the lastGrounded to coyoteTime
if (unlockedTrumpet) {
trumpet = 2;
LastOnGroundTime = Data.coyoteTime; //if so sets the lastGrounded to coyoteTime
if (unlockedTrumpet) {
trumpet = 2;
gameUI.ToggleTrumpet(true);
} else {
trumpet = -1;
}
wasGrappling = false;
isRegFalling = false;
} else {
// print("not jumping");
if(!_isJumpFalling && !isRegFalling) {
if(unlockedTrumpet) {
trumpet = 1;
gameUI.ToggleTrumpet(true);
} else {
trumpet = -1;
}
wasGrappling = false;
isRegFalling = false;
} else {
// print("not jumping");
if(!_isJumpFalling && !isRegFalling) {
if(unlockedTrumpet) {
trumpet = 1;
gameUI.ToggleTrumpet(true);
} else {
trumpet = -1;
}
isRegFalling = true;
}
}
//Right Wall Check
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)) && !IsWallJumping)
LastOnWallRightTime = Data.coyoteTime;
//Right Wall Check
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)) && !IsWallJumping)
LastOnWallLeftTime = Data.coyoteTime;
//Two checks needed for both left and right walls since whenever the play turns the wall checkPoints swap sides
LastOnWallTime = Mathf.Max(LastOnWallLeftTime, LastOnWallRightTime);
}
#endregion
#region JUMP CHECKS
if (IsJumping && RB.velocity.y <= 0)
{
IsJumping = false;
// print("isJumping " + IsJumping);
if (!IsWallJumping)
_isJumpFalling = true;
}
if (IsWallJumping && Time.time - _wallJumpStartTime > Data.wallJumpTime)
{
IsWallJumping = false;
}
if (LastOnGroundTime > 0 && !IsJumping && !IsWallJumping)
{
_isJumpCut = false;
if (!IsJumping)
_isJumpFalling = false;
}
//Jump
if (CanJump() && LastPressedJumpTime > 0)
{
IsJumping = true;
IsWallJumping = false;
_isJumpCut = false;
_isJumpFalling = false;
Jump();
if (!IsGrounded() && in_range && trumpet > 0)
{
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
enemy.GetComponent<EnemyPatrol>().DefeatEnemy();
enemy = null;
in_range = false;
}
else if (!IsGrounded() && !in_range && trumpet > 0)
{
trumpet -= 1;
}
// check if double jump, play sound
if (trumpet == 0) {
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
isRegFalling = true;
}
}
// stop sound if needed
if (soundPlaying && (isRegFalling || IsJumping || _isJumpFalling)) {
print("footsteps stop");
audioSource.Stop();
soundPlaying = false;
}
//Right Wall Check
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)) && !IsWallJumping)
LastOnWallRightTime = Data.coyoteTime;
//WALL JUMP
// else if (CanWallJump() && LastPressedJumpTime > 0)
// {
// IsWallJumping = true;
// IsJumping = false;
// _isJumpCut = false;
// _isJumpFalling = false;
// _wallJumpStartTime = Time.time;
// _lastWallJumpDir = (LastOnWallRightTime > 0) ? -1 : 1;
//
// WallJump(_lastWallJumpDir);
// }
#endregion
//Right Wall Check
if (((Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && !IsFacingRight)
|| (Physics2D.OverlapBox(this.transform.position, _wallCheckSize, 0, _groundLayer) && IsFacingRight)) && !IsWallJumping)
LastOnWallLeftTime = Data.coyoteTime;
#region GRAPPLE CHECKS
// set wasGrappling to true if the player starts grappling
if (grapplingRope.isGrappling) {
wasGrappling = true;
}
#endregion
#region SLIDE CHECKS
if (CanSlide() && ((LastOnWallLeftTime > 0 && _moveInput.x < 0) || (LastOnWallRightTime > 0 && _moveInput.x > 0)))
IsSliding = true;
else
IsSliding = false;
#endregion
#region GRAVITY
//Higher gravity if we've released the jump input or are falling
if (IsSliding)
{
SetGravityScale(0);
}
else if (RB.velocity.y < 0 && _moveInput.y < 0)
{
//Much higher gravity if holding down
SetGravityScale(Data.gravityScale * Data.fastFallGravityMult);
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFastFallSpeed));
}
else if (_isJumpCut)
{
//Higher gravity if jump button released
SetGravityScale(Data.gravityScale * Data.jumpCutGravityMult);
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
}
else if ((IsJumping || IsWallJumping || _isJumpFalling) && Mathf.Abs(RB.velocity.y) < Data.jumpHangTimeThreshold)
{
SetGravityScale(Data.gravityScale * Data.jumpHangGravityMult);
}
else if (RB.velocity.y < 0)
{
//Higher gravity if falling
SetGravityScale(Data.gravityScale * Data.fallGravityMult);
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
}
else
{
//Default gravity if standing on a platform or moving upwards
SetGravityScale(Data.gravityScale);
}
#endregion
#region SOUND CHECKS
if (!IsJumping && !_isJumpFalling && !isRegFalling && _moveInput.x != 0) {
if (!soundPlaying) {
// print("footsteps PLAY");
audioSource.Play();
soundPlaying = true;
}
} else if (soundPlaying && audioSource.clip.name == "footsteps") {
// print("footsteps stop");
audioSource.Stop();
soundPlaying = false;
}
#endregion
#region UPDATE UI
if (trumpet == 0) {
gameUI.ToggleTrumpet(false);
}
/*if (isDashing)
{
gameUI.ToggleClarinet(false);
print("toggle clarinet false?");
}*/
#endregion
//Two checks needed for both left and right walls since whenever the play turns the wall checkPoints swap sides
LastOnWallTime = Mathf.Max(LastOnWallLeftTime, LastOnWallRightTime);
}
#endregion
#region JUMP CHECKS
if (IsJumping && RB.velocity.y <= 0)
{
IsJumping = false;
// print("isJumping " + IsJumping);
if (!IsWallJumping)
_isJumpFalling = true;
}
if (IsWallJumping && Time.time - _wallJumpStartTime > Data.wallJumpTime)
{
IsWallJumping = false;
}
if (LastOnGroundTime > 0 && !IsJumping && !IsWallJumping)
{
_isJumpCut = false;
if (!IsJumping)
_isJumpFalling = false;
}
//Jump
if (CanJump() && LastPressedJumpTime > 0)
{
IsJumping = true;
IsWallJumping = false;
_isJumpCut = false;
_isJumpFalling = false;
Jump();
if (!IsGrounded() && in_range && trumpet > 0)
{
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
enemy.GetComponent<EnemyPatrol>().DefeatEnemy();
enemy = null;
in_range = false;
}
else if (!IsGrounded() && !in_range && trumpet > 0)
{
trumpet -= 1;
}
// check if double jump, play sound
if (trumpet == 0) {
gameObject.transform.Find("Trumpet").GetComponent<AudioSource>().Play();
}
}
// stop sound if needed
if (soundPlaying && (isRegFalling || IsJumping || _isJumpFalling)) {
print("footsteps stop");
audioSource.Stop();
soundPlaying = false;
}
//WALL JUMP
// else if (CanWallJump() && LastPressedJumpTime > 0)
// {
// IsWallJumping = true;
// IsJumping = false;
// _isJumpCut = false;
// _isJumpFalling = false;
// _wallJumpStartTime = Time.time;
// _lastWallJumpDir = (LastOnWallRightTime > 0) ? -1 : 1;
//
// WallJump(_lastWallJumpDir);
// }
#endregion
#region GRAPPLE CHECKS
// set wasGrappling to true if the player starts grappling
if (grapplingRope.isGrappling) {
wasGrappling = true;
}
#endregion
#region SLIDE CHECKS
if (CanSlide() && ((LastOnWallLeftTime > 0 && _moveInput.x < 0) || (LastOnWallRightTime > 0 && _moveInput.x > 0)))
IsSliding = true;
else
IsSliding = false;
#endregion
#region GRAVITY
//Higher gravity if we've released the jump input or are falling
if (IsSliding)
{
SetGravityScale(0);
}
else if (RB.velocity.y < 0 && _moveInput.y < 0)
{
//Much higher gravity if holding down
SetGravityScale(Data.gravityScale * Data.fastFallGravityMult);
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFastFallSpeed));
}
else if (_isJumpCut)
{
//Higher gravity if jump button released
SetGravityScale(Data.gravityScale * Data.jumpCutGravityMult);
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
}
else if ((IsJumping || IsWallJumping || _isJumpFalling) && Mathf.Abs(RB.velocity.y) < Data.jumpHangTimeThreshold)
{
SetGravityScale(Data.gravityScale * Data.jumpHangGravityMult);
}
else if (RB.velocity.y < 0)
{
//Higher gravity if falling
SetGravityScale(Data.gravityScale * Data.fallGravityMult);
//Caps maximum fall speed, so when falling over large distances we don't accelerate to insanely high speeds
RB.velocity = new Vector2(RB.velocity.x, Mathf.Max(RB.velocity.y, -Data.maxFallSpeed));
}
else
{
//Default gravity if standing on a platform or moving upwards
SetGravityScale(Data.gravityScale);
}
#endregion
#region SOUND CHECKS
if (!IsJumping && !_isJumpFalling && !isRegFalling && _moveInput.x != 0) {
if (!soundPlaying) {
// print("footsteps PLAY");
audioSource.Play();
soundPlaying = true;
}
} else if (soundPlaying && audioSource.clip.name == "footsteps") {
// print("footsteps stop");
audioSource.Stop();
soundPlaying = false;
}
#endregion
#region UPDATE UI
if (trumpet == 0) {
gameUI.ToggleTrumpet(false);
}
/*if (isDashing)
{
gameUI.ToggleClarinet(false);
print("toggle clarinet false?");
}*/
#endregion
}
private void FixedUpdate()
{
if(!isDashing){
//Handle Run
if (IsWallJumping)
Run(Data.wallJumpRunLerp);
@ -353,21 +337,6 @@ public class PlayerMovement : MonoBehaviour
//Handle Slide
if (IsSliding)
Slide();
}
}
void FreezeControl()
{
if(!isFrozen)
{
tempGrav = Data.gravityStrength;
tempFall = Data.fallGravityMult;
}
Data.gravityStrength = 0;
Data.fallGravityMult = 0;
isFrozen = true;
}
#region INPUT CALLBACKS