droplet script

This commit is contained in:
orsolya-st
2026-06-06 17:28:30 +02:00
parent 9c29e3d9b1
commit 87c5b927b5
7 changed files with 35 additions and 16 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 5321372118810808216} - component: {fileID: 5321372118810808216}
m_Layer: 0 m_Layer: 0
m_Name: Branch m_Name: Branch
m_TagString: Untagged m_TagString: Platform
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@@ -105,7 +105,7 @@ GameObject:
- component: {fileID: 1462837664068369080} - component: {fileID: 1462837664068369080}
m_Layer: 0 m_Layer: 0
m_Name: LeaveObstacle m_Name: LeaveObstacle
m_TagString: Untagged m_TagString: Platform
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 1230605949537068183} - component: {fileID: 1230605949537068183}
m_Layer: 0 m_Layer: 0
m_Name: RealBranch 1 m_Name: RealBranch 1
m_TagString: Untagged m_TagString: Platform
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 1230605949537068183} - component: {fileID: 1230605949537068183}
m_Layer: 0 m_Layer: 0
m_Name: RealBranch m_Name: RealBranch
m_TagString: Untagged m_TagString: Platform
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
+9 -3
View File
@@ -1,6 +1,5 @@
using System; using System.Collections;
using UnityEngine; using UnityEngine;
using Object = System.Object;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
public class DamageHandler : MonoBehaviour public class DamageHandler : MonoBehaviour
@@ -60,6 +59,11 @@ public class DamageHandler : MonoBehaviour
private void OnCollisionEnter2D(Collision2D other) private void OnCollisionEnter2D(Collision2D other)
{ {
if (other.collider.CompareTag("Minidrop")){
UpdateHealth(0.2f);
}
//on collision check fall damage
float fallSpeed = lastYVelocity; float fallSpeed = lastYVelocity;
if (fallSpeed < -threshold) if (fallSpeed < -threshold)
{ {
@@ -70,8 +74,10 @@ public class DamageHandler : MonoBehaviour
public void UpdateHealth(float health) public void UpdateHealth(float health)
{ {
this.health = health; this.health = health;
if (health > maxHealth) this.health = maxHealth;
Transform transform = GetComponent<Transform>(); Transform transform = GetComponent<Transform>();
float healthScaling = minSize + (1 - minSize) * (this.health / maxHealth); float healthScaling = minSize + (1 - minSize) * (this.health / maxHealth);
//adjust size based on health //adjust size based on health
+21 -9
View File
@@ -8,7 +8,7 @@ public class DropletMovement : MonoBehaviour
private Collider2D characterCollider; private Collider2D characterCollider;
// helper variables // helper variables
private bool isGrounded = true; private bool isGrounded = false;
private float facingDirection = 1f; private float facingDirection = 1f;
private bool isDropping = false; private bool isDropping = false;
private float fallTimer; private float fallTimer;
@@ -40,7 +40,7 @@ public class DropletMovement : MonoBehaviour
{ {
//dashing //dashing
if (isDashing) if (isDashing || isGrounded == false)
{ {
return; return;
} }
@@ -91,20 +91,17 @@ public class DropletMovement : MonoBehaviour
private void FixedUpdate() private void FixedUpdate()
{ {
if (isDashing || isDropping) if (isDashing || isDropping)
{ {
return; return;
} // was here before }
//wind
float windForce = 0f; float windForce = 0f;
if (WindManager.Instance != null) if (WindManager.Instance != null)
{ {
windForce = WindManager.Instance.CurrentWindForce; windForce = WindManager.Instance.CurrentWindForce;
} }
rb.linearVelocity = new Vector2(movement.x * moveSpeed + windForce, rb.linearVelocity.y); rb.linearVelocity = new Vector2(movement.x * moveSpeed + windForce, rb.linearVelocity.y);
//used to be rb.linearVelocity = new Vector2(movement.x * moveSpeed, rb.linearVelocity.y);
} }
private void OnTriggerEnter2D(Collider2D other) private void OnTriggerEnter2D(Collider2D other)
@@ -151,8 +148,23 @@ public class DropletMovement : MonoBehaviour
} }
private void OnCollisionEnter2D(Collision2D col) private void OnCollisionEnter2D(Collision2D col)
{
if (col.collider.CompareTag("Platform") && rb.linearVelocity.y == 0)
{
isGrounded = true;
}
else
{
isGrounded = false;
}
}
private void OnCollisionExit2D(Collision2D collision)
{ {
isGrounded = true; if (collision.collider.CompareTag("Platform"))
{
isGrounded = false;
}
} }
+1
View File
@@ -7,6 +7,7 @@ TagManager:
- Border - Border
- Hole - Hole
- Minidrop - Minidrop
- Platform
layers: layers:
- Default - Default
- TransparentFX - TransparentFX