비행 몬스터 추가 및 맵 오브젝트 배치 수정

This commit is contained in:
Mingu Kim
2025-07-23 21:07:34 +09:00
parent 1676127add
commit 745ce065e8
13 changed files with 1718 additions and 104 deletions

View File

@@ -0,0 +1,51 @@
using UnityEngine;
public class FlyingEnemyMove : MonoBehaviour
{
// TODO : 임시 코드
public float moveSpeed = 3f;
public float jumpForce = 5f;
public float gravityScale = 0f;
public float groundCheckDistance = 0.2f; // 지면 감지를 위한 거리
public LayerMask groundLayer; // 지면 레이어 마스크
private Rigidbody2D rb;
private bool isGrounded; // 지면 여부
void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.gravityScale = gravityScale;
}
void FixedUpdate()
{
// 지면 감지
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundCheckDistance, groundLayer);
// 이동 로직 (예시: 좌우 이동)
float horizontalInput = Random.Range(-1f, 1f); // 랜덤 이동
Vector2 velocity = rb.linearVelocity;
velocity.x = horizontalInput * moveSpeed;
rb.linearVelocity = velocity;
// 점프 (예시: 일정 확률로 점프)
if (isGrounded && Random.value < 0.01f) // 1% 확률로 점프
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
void OnCollisionEnter2D(Collision2D collision)
{
// 충돌 처리 로직 (예시: 벽에 닿으면 튕겨나가기)
if (collision.gameObject.CompareTag("Wall"))
{
// 충돌한 방향 반대로 힘을 가하여 튕겨내기
Vector2 bounceDirection = (transform.position - collision.transform.position).normalized;
rb.AddForce(bounceDirection * 5f, ForceMode2D.Impulse);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 17df5f47e9ea4f34dbc898874d79b31e