Share Tạo 2D Platformer Game với Godot] Phần 8: Thiết kế kẻ thù

congluanbui

New member
Ach làm thế nào để làm trò chơi ** Cách khiến kẻ thù di chuyển trên bề mặt nổi trong Godot **

Trong hướng dẫn trước, tôi đã chỉ cho bạn cách tạo ra kẻ thù cơ bản nhất, trong hướng dẫn này, tôi sẽ chỉ cho bạn cách làm cho kẻ thù di chuyển trên bề mặt nổi.

** Thêm nút **

Đầu tiên, bạn thêm một nút mới, Raycast2D (đây là nút được sử dụng để truy vấn các mục tiêu va chạm).

`` `
Mở rộng động học2d

var chuyendong = vector2 ()
var tocdo = 500
var inluc = 5
var Huong_dichuyen = 1

Func _Physics_Process (Delta):
chuyendong.x = tocdo * hUong_dichuyen
chuyendong.y += inluc
Chuyendong = Move_and_Slide (Chuyendong, Vector2.up)
Animation.Play ("Dichuyen")
Nếu is_on_wall ():
HUONG_DICHuyEN = HUONG_DICHUYEN * -1
scale.x = scale.y * hUong_dichuyen
Nếu $ raycast2d.is_colliding () == false:
HUONG_DICHuyEN = HUONG_DICHUYEN * -1
scale.x = scale.y * hUong_dichuyen
`` `

** Cách vận hành **

Raycast sẽ kiểm tra xem kẻ thù có đến được góc của nền tảng không.Nếu nó có, kẻ thù sẽ quay lại và tiếp tục di chuyển.

**Bản tóm tắt**

Trong hướng dẫn này, bạn đã học được cách làm cho kẻ thù di chuyển trên một bề mặt nổi trong Godot.Trong hướng dẫn tiếp theo, tôi sẽ chỉ cho bạn cách khiến kẻ thù di chuyển giữa các cấp độ và giết kẻ thù.
=======================================
ach How to make games **How to make the enemy move on a floating surface in Godot**

In the previous tutorial, I showed you how to create the most basic enemy, in this tutorial I will show you how to make the enemy move on a floating surface.

**Add node**

First, you add a new node, Raycast2D (this is the node used to query the collision targets).

```
extends KinematicBody2D

var chuyendong = Vector2()
var tocdo = 500
var inluc = 5
var huong_dichuyen = 1

func _physics_process(delta):
chuyendong.x = tocdo * huong_dichuyen
chuyendong.y += inluc
chuyendong = Move_and_slide(chuyendong, vector2.up)
Animation.play("Dichuyen")
if is_on_wall():
huong_dichuyen = huong_dichuyen * -1
scale.x = scale.y * huong_dichuyen
if $raycast2d.is_colliding() == False:
huong_dichuyen = huong_dichuyen * -1
scale.x = scale.y * huong_dichuyen
```

**How to operate**

The raycast will check if the enemy has reached the corner of the platform. If it has, the enemy will turn around and continue moving.

**Summary**

In this tutorial, you learned how to make the enemy move on a floating surface in Godot. In the next tutorial, I will show you how to make the enemy move between levels and kill enemies.
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top