Fix there being a chance to jump multiple times at once
This commit is contained in:
4 files changed
+19
-5
No files matched your search
@@ -47,6 +47,7 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
|
||||
public readonly List<GameObject> berries = new();
|
||||
private readonly List<int> noGravityBerries = new();
|
||||
private bool hasJumped = false;
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
@@ -211,12 +212,14 @@ public class AutoGamePlayer : MonoBehaviour {
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f * canvasRect.lossyScale.y);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f * canvasRect.lossyScale.y);
|
||||
}
|
||||
if (!IsGrounded()) hasJumped = false;
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
|
||||
public readonly List<GameObject> berries = new();
|
||||
private readonly List<int> noGravityBerries = new();
|
||||
private bool hasJumped = false;
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
@@ -165,12 +166,14 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 220f);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f);
|
||||
}
|
||||
if (!IsGrounded()) hasJumped = false;
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
}
|
||||
@@ -346,12 +349,14 @@ public class CustomGamePlayer : MonoBehaviour {
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f * canvasRect.lossyScale.y);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f * canvasRect.lossyScale.y);
|
||||
}
|
||||
if (!IsGrounded()) hasJumped = false;
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public class GamePlayer : MonoBehaviour {
|
||||
|
||||
public readonly List<GameObject> berries = new();
|
||||
private readonly List<int> noGravityBerries = new();
|
||||
private bool hasJumped = false;
|
||||
|
||||
internal bool IsGrounded() => Physics2D.Distance(bird.GetComponent<CircleCollider2D>(), groundCollider).distance <= 0.1f;
|
||||
|
||||
@@ -151,12 +152,14 @@ public class GamePlayer : MonoBehaviour {
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f || speedyLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f * canvasRect.lossyScale.y);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f * canvasRect.lossyScale.y);
|
||||
}
|
||||
if (!IsGrounded()) hasJumped = false;
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
private readonly Dictionary<MultiplayerBerry, GameObject> berries = new();
|
||||
private readonly List<MultiplayerUser> players = new();
|
||||
private float lastMoveSentTime = -1f;
|
||||
private bool hasJumped = false;
|
||||
|
||||
private Image bird;
|
||||
[SerializeField] private GameObject birdTemplate;
|
||||
@@ -225,12 +226,14 @@ public class MultiplayerGamePlayer : MonoBehaviour {
|
||||
bird.transform.localScale = new UnityEngine.Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
if (doMoveLeft || doMoveRight) groundCollider.transform.position = new(bird.transform.position.x, groundCollider.transform.position.y);
|
||||
if (doJump && IsGrounded()) {
|
||||
if (doJump && IsGrounded() && !hasJumped) {
|
||||
hasJumped = true;
|
||||
AudioSource.PlayClipAtPoint(Resources.Load<AudioClip>("Sounds/Jump"), Camera.main.transform.position, 0.75f * BazookaManager.Instance.GetSettingSFXVolume());
|
||||
if (boostLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 480f * canvasRect.lossyScale.y);
|
||||
else if (slownessLeft > 0f) rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 300f * canvasRect.lossyScale.y);
|
||||
else rb.linearVelocity = new UnityEngine.Vector2(rb.linearVelocity.x, 380f * canvasRect.lossyScale.y);
|
||||
}
|
||||
if (!IsGrounded()) hasJumped = false;
|
||||
if (doBack) {
|
||||
TogglePause();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user