Basic enemy pathing implementation

This commit is contained in:
2023-09-02 17:42:07 -07:00
parent 549cb7a325
commit 334378932c
7 changed files with 160 additions and 132 deletions

View File

@@ -36,13 +36,13 @@ public partial class TestCharacter : CharacterBody3D
if (direction != Vector3.Zero)
{
velocity.X = direction.X * _speed;
velocity.Z = direction.Z * _speed * 2;
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Forward + Vector3.Up);
velocity.Z = direction.Z * _speed;
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed);
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed * 2);
velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed);
}
return velocity;
}

View File

@@ -1,7 +1,12 @@
using Godot;
public partial class TestEnemy : Node3D
public partial class TestEnemy : RigidBody3D
{
[Export]
private float _speed;
[Export]
private PathFollow3D _pathFollow;
public override void _Process(double delta)
{
var player = GetTree().GetFirstNodeInGroup("Player") as TestCharacter;
@@ -9,6 +14,11 @@ public partial class TestEnemy : Node3D
LookAt(player.Position);
}
public override async void _PhysicsProcess(double delta)
{
_pathFollow.Progress += _speed * (float)delta;
}
public void OnHit(Node node)
{
GD.Print("Hit detected");