need help with 2d boost
im making a boost mechanic in 2d similar to sonic rush games. the boost functions fine but theres a bug where, if grounded, if unlockDash is false, if boosting off an edge; my gravity will be set low so i float off the platform edge but it will be set really high so i cant jump.
ive integrated a dash mechanic with the boost so if unlock dash is false, the boost works normally but if unlockdash is true, the dash plays followed by the boost
ik its alot of code but any help will be appreciated!
void Boost()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
if (Grounded())
{
// Grounded Boost: Dash then Boost
StartCoroutine(DoBoost(true)); // Execute Boost after Dash
}
else if (!Grounded() && Input.GetButton("Dash"))
{
// Mid-air Boost: Dash then Boost (while holding dash button)
StartCoroutine(DoBoost(false)); // Execute Boost right after air dash
}
}
}
IEnumerator DoBoost(bool isGroundedBoost)
{
if (isGroundedBoost)
{
// Start Dash if grounded
int dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(dir dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost after Dash ends if grounded
boostTimer = 0f; // Reset boost timer
isBoosting = true;
bool boostCompleted = false;
// Don't disable gravity when grounded
if (!Grounded()) // Ensure gravity is only set to 0 when not grounded (mid-air boost)
{
rb.gravityScale = 0f; // Disable gravity only during mid-air boost
}
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime; // Increment boost time
rb.velocity = new Vector2(boostSpeed (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// Reset after boost ends
EndBoost(boostCompleted);
}
else
{
// In mid-air, boost directly after dash if Dash button is held
if (Input.GetButton("Dash"))
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Dash before boosting in mid-air
int dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(dir dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost continues
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// End boost after duration
EndBoost(boostCompleted);
im making a boost mechanic in 2d similar to sonic rush games. the boost functions fine but theres a bug where, if grounded, if unlockDash is false, if boosting off an edge; my gravity will be set low so i float off the platform edge but it will be set really high so i cant jump.
ive integrated a dash mechanic with the boost so if unlock dash is false, the boost works normally but if unlockdash is true, the dash plays followed by the boost
ik its alot of code but any help will be appreciated!
void Boost()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
if (Grounded())
{
// Grounded Boost: Dash then Boost
StartCoroutine(DoBoost(true)); // Execute Boost after Dash
}
else if (!Grounded() && Input.GetButton("Dash"))
{
// Mid-air Boost: Dash then Boost (while holding dash button)
StartCoroutine(DoBoost(false)); // Execute Boost right after air dash
}
}
}
IEnumerator DoBoost(bool isGroundedBoost)
{
if (isGroundedBoost)
{
// Start Dash if grounded
int dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(dir dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost after Dash ends if grounded
boostTimer = 0f; // Reset boost timer
isBoosting = true;
bool boostCompleted = false;
// Don't disable gravity when grounded
if (!Grounded()) // Ensure gravity is only set to 0 when not grounded (mid-air boost)
{
rb.gravityScale = 0f; // Disable gravity only during mid-air boost
}
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime; // Increment boost time
rb.velocity = new Vector2(boostSpeed (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// Reset after boost ends
EndBoost(boostCompleted);
}
else
{
// In mid-air, boost directly after dash if Dash button is held
if (Input.GetButton("Dash"))
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Dash before boosting in mid-air
int dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(dir dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost continues
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// End boost after duration
EndBoost(boostCompleted);
}
}
}
// Boost logic when unlockDash is false (only boost, no dash)
IEnumerator BoostWithoutDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Boost will happen with normal gravity when unlockDash is false
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Boost logic after dashing mid-air
IEnumerator BoostAfterDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost && !Grounded())
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Disable gravity only during the boost if you're not grounded (mid-air boost)
rb.gravityScale = 0; // Temporarily disable gravity when boosting in the air
// Apply boost horizontally during the boost
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Applies momentum after the boost ends
void ApplyMomentumAfterBoost()
{
// Store current velocity
float currentVelocityX = rb.velocity.x;
// Apply some momentum in the direction the player is facing, but without immediately stopping
StartCoroutine(MomentumCoroutine(currentVelocityX));
}
IEnumerator MomentumCoroutine(float initialVelocityX)
{
// Small momentum multiplier after the boost ends
float momentumMultiplier = 1.2f; // Adjust this value for desired
}
}
// Boost logic when unlockDash is false (only boost, no dash)
IEnumerator BoostWithoutDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Boost will happen with normal gravity when unlockDash is false
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Boost logic after dashing mid-air
IEnumerator BoostAfterDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost && !Grounded())
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Disable gravity only during the boost if you're not grounded (mid-air boost)
rb.gravityScale = 0; // Temporarily disable gravity when boosting in the air
// Apply boost horizontally during the boost
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Applies momentum after the boost ends
void ApplyMomentumAfterBoost()
{
// Store current velocity
float currentVelocityX = rb.velocity.x;
// Apply some momentum in the direction the player is facing, but without immediately stopping
StartCoroutine(MomentumCoroutine(currentVelocityX));
}
IEnumerator MomentumCoroutine(float initialVelocityX)
{
// Small momentum multiplier after the boost ends
float momentumMultiplier = 1.2f; // Adjust this value for desired
need help with 2d boost
im making a boost mechanic in 2d similar to sonic rush games. the boost functions fine but theres a bug where, if grounded, if unlockDash is false, if boosting off an edge; my gravity will be set low so i float off the platform edge but it will be set really high so i cant jump.
ive integrated a dash mechanic with the boost so if unlock dash is false, the boost works normally but if unlockdash is true, the dash plays followed by the boost
ik its alot of code but any help will be appreciated!
void Boost()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
if (Grounded())
{
// Grounded Boost: Dash then Boost
StartCoroutine(DoBoost(true)); // Execute Boost after Dash
}
else if (!Grounded() && Input.GetButton("Dash"))
{
// Mid-air Boost: Dash then Boost (while holding dash button)
StartCoroutine(DoBoost(false)); // Execute Boost right after air dash
}
}
}
IEnumerator DoBoost(bool isGroundedBoost)
{
if (isGroundedBoost)
{
// Start Dash if grounded
int _dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(_dir * dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost after Dash ends if grounded
boostTimer = 0f; // Reset boost timer
isBoosting = true;
bool boostCompleted = false;
// Don't disable gravity when grounded
if (!Grounded()) // Ensure gravity is only set to 0 when not grounded (mid-air boost)
{
rb.gravityScale = 0f; // Disable gravity only during mid-air boost
}
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime; // Increment boost time
rb.velocity = new Vector2(boostSpeed * (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// Reset after boost ends
EndBoost(boostCompleted);
}
else
{
// In mid-air, boost directly after dash if Dash button is held
if (Input.GetButton("Dash"))
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Dash before boosting in mid-air
int _dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(_dir * dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost continues
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed * (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// End boost after duration
EndBoost(boostCompleted);
im making a boost mechanic in 2d similar to sonic rush games. the boost functions fine but theres a bug where, if grounded, if unlockDash is false, if boosting off an edge; my gravity will be set low so i float off the platform edge but it will be set really high so i cant jump.
ive integrated a dash mechanic with the boost so if unlock dash is false, the boost works normally but if unlockdash is true, the dash plays followed by the boost
ik its alot of code but any help will be appreciated!
void Boost()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
if (Grounded())
{
// Grounded Boost: Dash then Boost
StartCoroutine(DoBoost(true)); // Execute Boost after Dash
}
else if (!Grounded() && Input.GetButton("Dash"))
{
// Mid-air Boost: Dash then Boost (while holding dash button)
StartCoroutine(DoBoost(false)); // Execute Boost right after air dash
}
}
}
IEnumerator DoBoost(bool isGroundedBoost)
{
if (isGroundedBoost)
{
// Start Dash if grounded
int _dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(_dir * dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost after Dash ends if grounded
boostTimer = 0f; // Reset boost timer
isBoosting = true;
bool boostCompleted = false;
// Don't disable gravity when grounded
if (!Grounded()) // Ensure gravity is only set to 0 when not grounded (mid-air boost)
{
rb.gravityScale = 0f; // Disable gravity only during mid-air boost
}
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime; // Increment boost time
rb.velocity = new Vector2(boostSpeed * (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// Reset after boost ends
EndBoost(boostCompleted);
}
else
{
// In mid-air, boost directly after dash if Dash button is held
if (Input.GetButton("Dash"))
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Dash before boosting in mid-air
int _dir = pState.lookingRight ? 1 : -1; // Use facing direction to determine dash direction
rb.velocity = new Vector2(_dir * dashSpeed, 0);
yield return new WaitForSeconds(dashTime);
// Boost continues
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed * (pState.lookingRight ? 1 : -1), rb.velocity.y); // Apply boost velocity in the direction the player is facing
yield return null;
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// End boost after duration
EndBoost(boostCompleted);
}
}
}
// Boost logic when unlockDash is false (only boost, no dash)
IEnumerator BoostWithoutDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Boost will happen with normal gravity when unlockDash is false
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed * initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Boost logic after dashing mid-air
IEnumerator BoostAfterDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost && !Grounded())
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Disable gravity only during the boost if you're not grounded (mid-air boost)
rb.gravityScale = 0; // Temporarily disable gravity when boosting in the air
// Apply boost horizontally during the boost
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed * initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Applies momentum after the boost ends
void ApplyMomentumAfterBoost()
{
// Store current velocity
float currentVelocityX = rb.velocity.x;
// Apply some momentum in the direction the player is facing, but without immediately stopping
StartCoroutine(MomentumCoroutine(currentVelocityX));
}
IEnumerator MomentumCoroutine(float initialVelocityX)
{
// Small momentum multiplier after the boost ends
float momentumMultiplier = 1.2f; // Adjust this value for desired
}
}
// Boost logic when unlockDash is false (only boost, no dash)
IEnumerator BoostWithoutDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost)
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Boost will happen with normal gravity when unlockDash is false
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed * initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Boost logic after dashing mid-air
IEnumerator BoostAfterDash()
{
if (Input.GetButton("Dash") && !isBoosting && canBoost && !Grounded())
{
isBoosting = true;
boostTimer = 0f;
bool boostCompleted = false;
// Store the initial direction to check for flipping
float initialDirection = pState.lookingRight ? 1 : -1; // Use facing direction to store initial direction
// Disable gravity only during the boost if you're not grounded (mid-air boost)
rb.gravityScale = 0; // Temporarily disable gravity when boosting in the air
// Apply boost horizontally during the boost
while (boostTimer < boostDuration && Input.GetButton("Dash"))
{
// If the player tries to flip, end the boost
if (Mathf.Sign(xAxis) != initialDirection)
{
EndBoost(false); // If boost didn't complete, don't start cooldown
yield break;
}
boostTimer += Time.deltaTime;
rb.velocity = new Vector2(boostSpeed * initialDirection, rb.velocity.y); // Apply boost in the correct direction
yield return null; // Wait for next frame
}
// If the full boost duration was used, start cooldown
if (boostTimer >= boostDuration)
{
boostCompleted = true;
}
// After boost ends, apply momentum and end boost
ApplyMomentumAfterBoost();
EndBoost(boostCompleted);
}
}
// Applies momentum after the boost ends
void ApplyMomentumAfterBoost()
{
// Store current velocity
float currentVelocityX = rb.velocity.x;
// Apply some momentum in the direction the player is facing, but without immediately stopping
StartCoroutine(MomentumCoroutine(currentVelocityX));
}
IEnumerator MomentumCoroutine(float initialVelocityX)
{
// Small momentum multiplier after the boost ends
float momentumMultiplier = 1.2f; // Adjust this value for desired
effect
float momentumDecay = 0.95f; // Decay rate to slowly reduce momentum over time
float momentumDuration = 0.5f; // Duration for the momentum effect
float timer = 0f;
// While the momentum duration hasn't ended, keep applying the momentum
while (timer < momentumDuration)
{
rb.velocity = new Vector2(initialVelocityX * momentumMultiplier, rb.velocity.y);
// Gradually reduce the momentum multiplier for a smooth slowdown
momentumMultiplier *= momentumDecay;
timer += Time.deltaTime;
yield return null; // Wait for the next frame
}
// Reset to normal velocity once momentum is done
rb.velocity = new Vector2(initialVelocityX, rb.velocity.y);
}
// End the boost by resetting necessary variables
void EndBoost(bool boostCompleted)
{
isBoosting = false;
boostTimer = 0f;
// If not grounded, restore gravity after boost ends
if (!Grounded())
{
rb.gravityScale = gravity; // Restore gravity when player is no longer grounded
}
// If the boost completed its full duration, trigger cooldown
if (boostCompleted)
{
StartCoroutine(BoostCooldown());
}
}
// Boost cooldown coroutine
IEnumerator BoostCooldown()
{
// Start cooldown only after the boost is completed
yield return new WaitForSeconds(boostCooldown);
canBoost = true;
}
void StartDash()
{
// Dash logic for both grounded and mid-air when "Dash" button is pressed, only if unlockDash is true
if (Input.GetButtonDown("Dash") && canDash && !dashed && dashCounter < maxDash)
{
Physics2D.IgnoreLayerCollision(7, 6, true);
StartCoroutine(Dash());
dashed = true;
}
if (Grounded())
{
dashCounter = 0;
maxDash = 1;
extraDash = false;
dashed = false;
}
if (extraDash && !Grounded())
{
maxDash = 2;
canDash = true;
dashed = false;
}
}
IEnumerator Dash()
{
Physics2D.IgnoreLayerCollision(7, 6, true);
canDash = false;
dashCounter++;
pState.dashing = true;
anim.SetTrigger("Dashing");
audioSource.PlayOneShot(dashSound);
if (!pState.gliding)
{
rb.gravityScale = 0;
}
int _dir = pState.lookingRight ? 1 : -1;
rb.velocity = new Vector2(_dir * dashSpeed, 0);
if (Grounded()) Instantiate(dashEffect, transform);
yield return new WaitForSeconds(dashTime);
canDashAttack = true;
trailRenderer.emitting = false;
Physics2D.IgnoreLayerCollision(7, 6, false);
rb.gravityScale = gravity;
pState.dashing = false;
// Dash cooldown logic
if (!pState.lanternDash)
{
yield return new WaitForSeconds(dashCooldown);
}
else
{
yield return new WaitForSeconds(0);
}
canDash = true;
yield return new WaitForSeconds(1);
canDashAttack = false;
}
https://redd.it/1hcwzzz
@r_Unity3D
float momentumDecay = 0.95f; // Decay rate to slowly reduce momentum over time
float momentumDuration = 0.5f; // Duration for the momentum effect
float timer = 0f;
// While the momentum duration hasn't ended, keep applying the momentum
while (timer < momentumDuration)
{
rb.velocity = new Vector2(initialVelocityX * momentumMultiplier, rb.velocity.y);
// Gradually reduce the momentum multiplier for a smooth slowdown
momentumMultiplier *= momentumDecay;
timer += Time.deltaTime;
yield return null; // Wait for the next frame
}
// Reset to normal velocity once momentum is done
rb.velocity = new Vector2(initialVelocityX, rb.velocity.y);
}
// End the boost by resetting necessary variables
void EndBoost(bool boostCompleted)
{
isBoosting = false;
boostTimer = 0f;
// If not grounded, restore gravity after boost ends
if (!Grounded())
{
rb.gravityScale = gravity; // Restore gravity when player is no longer grounded
}
// If the boost completed its full duration, trigger cooldown
if (boostCompleted)
{
StartCoroutine(BoostCooldown());
}
}
// Boost cooldown coroutine
IEnumerator BoostCooldown()
{
// Start cooldown only after the boost is completed
yield return new WaitForSeconds(boostCooldown);
canBoost = true;
}
void StartDash()
{
// Dash logic for both grounded and mid-air when "Dash" button is pressed, only if unlockDash is true
if (Input.GetButtonDown("Dash") && canDash && !dashed && dashCounter < maxDash)
{
Physics2D.IgnoreLayerCollision(7, 6, true);
StartCoroutine(Dash());
dashed = true;
}
if (Grounded())
{
dashCounter = 0;
maxDash = 1;
extraDash = false;
dashed = false;
}
if (extraDash && !Grounded())
{
maxDash = 2;
canDash = true;
dashed = false;
}
}
IEnumerator Dash()
{
Physics2D.IgnoreLayerCollision(7, 6, true);
canDash = false;
dashCounter++;
pState.dashing = true;
anim.SetTrigger("Dashing");
audioSource.PlayOneShot(dashSound);
if (!pState.gliding)
{
rb.gravityScale = 0;
}
int _dir = pState.lookingRight ? 1 : -1;
rb.velocity = new Vector2(_dir * dashSpeed, 0);
if (Grounded()) Instantiate(dashEffect, transform);
yield return new WaitForSeconds(dashTime);
canDashAttack = true;
trailRenderer.emitting = false;
Physics2D.IgnoreLayerCollision(7, 6, false);
rb.gravityScale = gravity;
pState.dashing = false;
// Dash cooldown logic
if (!pState.lanternDash)
{
yield return new WaitForSeconds(dashCooldown);
}
else
{
yield return new WaitForSeconds(0);
}
canDash = true;
yield return new WaitForSeconds(1);
canDashAttack = false;
}
https://redd.it/1hcwzzz
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
Missing 2D rendering option.
Hi, I've been trying to follow this tuturial:https://www.youtube.com/watch?v=WiDVoj5VQ4c&list=PLPV2KyIb3jR5xTUU7fitudKE6hCDA4Hso&index=26 and everything works until I try to go to create->shader->2D renderer the 2D render option doesn't show up. I have URP downloaded and am pretty sure it works correctly since I can create 2d lights. This is my first time working with shaders so I'm very lost. Thankfull for any help I can get.
https://redd.it/1hcy588
@r_Unity3D
Hi, I've been trying to follow this tuturial:https://www.youtube.com/watch?v=WiDVoj5VQ4c&list=PLPV2KyIb3jR5xTUU7fitudKE6hCDA4Hso&index=26 and everything works until I try to go to create->shader->2D renderer the 2D render option doesn't show up. I have URP downloaded and am pretty sure it works correctly since I can create 2d lights. This is my first time working with shaders so I'm very lost. Thankfull for any help I can get.
https://redd.it/1hcy588
@r_Unity3D
YouTube
How to make 2D GLOW in Unity!
In this video we create an awesome Glow effect for extra flare!
► Check out Popcore! https://popcore.com/career
● Download the project: https://github.com/Brackeys/2D-Glow
● Get Gothicvania Church Pack: https://assetstore.unity.com/packages/2d/cha…
► Check out Popcore! https://popcore.com/career
● Download the project: https://github.com/Brackeys/2D-Glow
● Get Gothicvania Church Pack: https://assetstore.unity.com/packages/2d/cha…
Media is too big
VIEW IN TELEGRAM
I've started work on a VR heisting game! If you have any suggestions of vault cracking methods, or just any at all, let me know!
https://redd.it/1hcy7yd
@r_Unity3D
https://redd.it/1hcy7yd
@r_Unity3D
Make hand-drawn sprites clear
Is there a way to make hand-drawn sprites look crisp/clear on unity? Like sprites made on drawing apps like IbisPaint X? Usually when I import the sprites, they either look pixelated or blurry no matter how many changes I make in Inspector. Thank you!
https://redd.it/1hd2x9d
@r_Unity3D
Is there a way to make hand-drawn sprites look crisp/clear on unity? Like sprites made on drawing apps like IbisPaint X? Usually when I import the sprites, they either look pixelated or blurry no matter how many changes I make in Inspector. Thank you!
https://redd.it/1hd2x9d
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
Can someone figure out while this slide method doesnt work?
Ive been trying to figure this out for so long and nothing seems to work
private IEnumerator HandleSlide()
{
animator.SetTrigger("Slide");
nextAttackTime = Time.time + 1f / SlideRate;
rb.velocity = Vector2.zero;
rb.angularVelocity = 0;
rb.gravityScale = 0;
// Vector2 slideDirection = transform.localScale.x > 0 ? Vector2.right : Vector2.left;
rb.velocity = new Vector2(transform.localScale.x * SlideForce, 0f);
float animationDuration = GetAnimationDuration("Slide");
float elapsedTime = 0f;
while (elapsedTime < animationDuration)
{
Collider2D[\] hitEnemies = Physics2D.OverlapCircleAll(hurtBox.position, attackRange, enemyLayers);
if (hitEnemies.Length > 0)
{
foreach (Collider2D enemy in hitEnemies)
{
enemy.GetComponent<Player2Health>().TakeDamage(SlideDamage);
}
break; // makes so the loop ends if collided
}
elapsedTime += Time.deltaTime;
yield return null;
}
}
https://redd.it/1hczhhj
@r_Unity3D
Ive been trying to figure this out for so long and nothing seems to work
private IEnumerator HandleSlide()
{
animator.SetTrigger("Slide");
nextAttackTime = Time.time + 1f / SlideRate;
rb.velocity = Vector2.zero;
rb.angularVelocity = 0;
rb.gravityScale = 0;
// Vector2 slideDirection = transform.localScale.x > 0 ? Vector2.right : Vector2.left;
rb.velocity = new Vector2(transform.localScale.x * SlideForce, 0f);
float animationDuration = GetAnimationDuration("Slide");
float elapsedTime = 0f;
while (elapsedTime < animationDuration)
{
Collider2D[\] hitEnemies = Physics2D.OverlapCircleAll(hurtBox.position, attackRange, enemyLayers);
if (hitEnemies.Length > 0)
{
foreach (Collider2D enemy in hitEnemies)
{
enemy.GetComponent<Player2Health>().TakeDamage(SlideDamage);
}
break; // makes so the loop ends if collided
}
elapsedTime += Time.deltaTime;
yield return null;
}
}
https://redd.it/1hczhhj
@r_Unity3D
Spaghetti code, Code Optimization, Trojan, Packet Loss, Remote Access. Help me brainstorm more of these.
https://redd.it/1hd8o8u
@r_Unity3D
https://redd.it/1hd8o8u
@r_Unity3D
This is the best feedback I've ever gotten for a game. Some players have a hilarious sense of humor :D
https://redd.it/1hd9jol
@r_Unity3D
https://redd.it/1hd9jol
@r_Unity3D
Media is too big
VIEW IN TELEGRAM
I showed my Unity game for the first time at an indie game festival in Seoul! :D (90% of the other devs used Unity as well) It was very exciting seeing my game played blind by others!
https://redd.it/1hda70n
@r_Unity3D
https://redd.it/1hda70n
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
Playtesting available for upcoming game, Xenopurge an Alien-inspired Auto Battler
https://redd.it/1hd7f6g
@r_Unity3D
https://redd.it/1hd7f6g
@r_Unity3D