Как заставить врага двигаться к игроку в Godot4 с помощью C#C#

Место общения программистов C#
Ответить
Гость
 Как заставить врага двигаться к игроку в Godot4 с помощью C#

Сообщение Гость »


I'm making a 2d top-down game in Godot 4 with C# and I can't get the enemy AI to move toward the player. The only time it follows the player is when the player in under the enemy and touching the enemy.

This is my code for the enemy movement:

Код: Выделить всё

public override void _PhysicsProcess(double delta) {     Move();     MoveAndSlide(); } public void Move() {     if (_player != null)     {         LookAt(_player.GlobalPosition);         Vector2 direction = (GlobalPosition - _player.GlobalPosition).Normalized();         Velocity = direction * Speed;     }     else     {         Velocity = Vector2.Zero;     } } 


Источник: https://stackoverflow.com/questions/777 ... th-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»