Chasing the player :: Godot 4 RecipesChasing the player :: Godot 4 Recipeskidscancode.org



3ca8d535f1db37a83eee98b21fd70403898f7362acee76b2a259





https://www.youtube.com/watch?v=9u59U-DWNJs&t=305s

How to Create an ENEMY In Godot 4In this video we are going to go over how to create an enemy in godot 4, An enemy is one of the most important things in a game, if you dont have smooth good...www.youtube.com


https://kidscancode.org/godot_recipes/4.x/ai/chasing/index.html

ํ•ด๋‹น ๊ฐ•์ขŒ ์ฐธ๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค.



๋‹ค์Œ์€ ์ œ ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค.


extends CharacterBody2D


var run_speed = 50

var player = null


func _physics_process(delta):

velocity = Vector2.ZERO

if player:

velocity = position.direction_to(player.position) * run_speed

move_and_slide()


func _on_detection_area_body_entered(body):

player = body


func _on_detection_area_body_exited(body):

player = null







==================================================================================================


ํ˜ผ์ž ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.


position -> global_position์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋‹ˆ๊นŒ ๋”ฐ๋ผ์˜ค๋„ค์š”.


์•„๋งˆ ์ธ์Šคํ„ด์Šคํ™” ์ดํ›„์— position์„ ์‚ฌ์šฉํ•œ ๊ฒƒ ๋•Œ๋ฌธ์— ์ €๋Ÿฐ ํ˜„์ƒ์ด ์ƒ๊ธด ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.