일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- topdown
- click
- 탑다운
- euler
- Event
- addEventListener
- jQuery
- className
- javascript
- intervals
- classList
- Lerp
- vsCode
- 코딩
- PYTHON
- 연습
- 도트
- 종속변수
- setItem
- Quaternion
- Unity
- 자주 사용하는 Quaternion 함수
- 회전
- 웹스크래핑
- 2D
- 독립변수
- 도린이
- wsl
- 픽셀
- getItem
Archives
- Today
- Total
쫑가 과정
적 AI. 플레이어 따라가기. 본문
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Enemy : MonoBehaviour
{
[SerializeField] protected float moveSpeed;
[SerializeField] protected Transform player;
private protected Rigidbody2D rb;
private protected Vector2 movement;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyYul : Enemy
{
private void Start()
{
rb = this.GetComponent<Rigidbody2D>();
}
private void Update()
{
Vector3 direction = player.position - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
rb.rotation = angle;
direction.Normalize();
movement = direction;
}
private void FixedUpdate()
{
MoveCharacter(movement);
}
private void MoveCharacter(Vector2 direction)
{
rb.MovePosition((Vector2)transform.position + (direction * moveSpeed * Time.deltaTime));
}
}
'Unity2D > 구현' 카테고리의 다른 글
2D sorting / 2d 오브젝트 렌더러 우선순위 정하기. (1) | 2022.02.16 |
---|---|
2d 클릭 2) 더블 클릭 (0) | 2022.01.26 |
2d 클릭 1) 오브젝트 클릭 (0) | 2022.01.24 |
Comments