53 lines
1.0 KiB
C#
53 lines
1.0 KiB
C#
using Godot;
|
|
using System;
|
|
using Movementtests.player_controller.Scripts;
|
|
|
|
|
|
[GlobalClass]
|
|
public partial class FirstEnemy : CharacterBody3D, ISpawnable
|
|
{
|
|
[Export]
|
|
public Node3D Target { get; set; }
|
|
|
|
[Export]
|
|
public EnemyInitInputs Inputs;
|
|
|
|
private RayCast3D _wallInFrontRayCast;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_wallInFrontRayCast = GetNode<RayCast3D>("WallInFrontRayCast");
|
|
}
|
|
|
|
public Resource GetSpawnInitResource()
|
|
{
|
|
return Inputs;
|
|
}
|
|
|
|
public void TestMethod()
|
|
{
|
|
GD.Print("I'm an enemy");
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
var target = Target.GlobalPosition;
|
|
var direction = (target - GlobalPosition).Normalized();
|
|
|
|
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
|
|
LookAt(targetPlane);
|
|
|
|
var velocity = Velocity;
|
|
velocity.X = direction.X * Inputs.Speed;
|
|
velocity.Z = direction.Z * Inputs.Speed;
|
|
|
|
if (_wallInFrontRayCast.IsColliding())
|
|
velocity.Y = Inputs.Speed;
|
|
else if (!IsOnFloor())
|
|
velocity += GetGravity() * (float)delta;
|
|
|
|
Velocity = velocity;
|
|
MoveAndSlide();
|
|
}
|
|
}
|