Merge branch 'main' into damage-handling

This commit is contained in:
go38coz
2026-06-06 14:08:08 +02:00
60 changed files with 3846 additions and 1041 deletions
+80
View File
@@ -4,11 +4,16 @@ using System.Collections;
public class DropletMovement : MonoBehaviour
{
private Rigidbody2D rb;
private Collider2D characterCollider;
// helper variables
private bool isGrounded = true;
private float facingDirection = 1f;
private bool isDropping = false;
private float fallAngleThreshold = -45f;
private float fallTimer;
private bool isFalling;
public float maxFallTime = 0.5f;
// movement
private Vector2 movement;
@@ -23,14 +28,37 @@ public class DropletMovement : MonoBehaviour
public float dashingCooldown = 1f;
[SerializeField] private TrailRenderer tr;
[SerializeField] private Animator animator;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
[System.Obsolete]
void Update()
{
//reset falltimer when start the jump
if ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) && isGrounded)
{
fallTimer = 0f; //jump resets falltime
}
//fall damage
if (isGrounded && fallTimer > 0.6f)
{
Destroy(gameObject); //TODO
}
//handle jump/midair variables
if (isGrounded)
{
isFalling = false;
} else
{
HandleMidairLogic();
}
//dashing
if (isDashing)
@@ -48,6 +76,18 @@ public class DropletMovement : MonoBehaviour
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpingPower);
}
if (movement.x > 0) {
animator.SetBool("WalkingRight", true);
animator.SetBool("WalkingLeft", false);
} else if (movement.x <0 && movement.x != 0)
{
animator.SetBool("WalkingRight", false);
animator.SetBool("WalkingLeft", true);
} else
{
animator.SetBool("WalkingRight", false);
animator.SetBool("WalkingLeft", false);
}
if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
{
StartCoroutine(Dash());
@@ -72,6 +112,46 @@ public class DropletMovement : MonoBehaviour
rb.linearVelocity = new Vector2(movement.x * moveSpeed, rb.linearVelocity.y);
}
private void OnTriggerEnter2D(Collider2D other)
{
/*if (other.CompareTag("Border"))
{
Destroy(gameObject); //for now it destroys the droplet
Debug.Log("Droplet dropped down, animation, game end!");
}*/
//Hole
if (other.CompareTag("Hole"))
{
Destroy(gameObject);
Debug.Log("Fell in hole!");
}
}
[System.Obsolete]
private void HandleMidairLogic()
{
if (rb.linearVelocity.y >= 0)
{
isFalling = false;
fallTimer = 0f;
return;
}
float movementAngle = Mathf.Atan2(rb.velocity.y, rb.velocity.x) * Mathf.Rad2Deg;
//Degrees: 0 - right, 90 - up, -90 - down --> downwards is beteen -90 and -180
//Standard treshhold (degree) = -45 --> between -45 and -135 degrees is falling (instead of jumping)
bool fallingDown = (movementAngle < fallAngleThreshold && movementAngle > (-180f - fallAngleThreshold));
if (fallingDown || rb.velocity.x == 0)
{
isFalling = true;
fallTimer += Time.deltaTime;
Debug.Log($"Fall time: {fallTimer:F2} seconds");
}
}
private IEnumerator Dash()
{
canDash = false;