improved pathfinding

This commit is contained in:
2023-02-27 19:14:41 +01:00
parent a94ee84718
commit 86d6563975
5 changed files with 42 additions and 48 deletions

View File

@@ -0,0 +1,17 @@
using Godot;
using System;
public partial class slime : CharacterBody2D
{
[Export] int speed = 70;
Vector2 motion = Vector2.Zero;
public override void _Ready() => GetNode<AnimatedSprite2D>("animated_sprite_2d").Play();
public override void _PhysicsProcess(double delta)
{
if (GetNode<VisibleOnScreenNotifier2D>("visible_notifier_2d").IsOnScreen())
motion = Position.DirectionTo(player.globalPlayerPosition) * speed;
else motion = Vector2.Zero;
Velocity = motion;
MoveAndSlide();
}
}