Files
MovementTests/scenes/enemies/FirstEnemy.cs
Minimata fd3eb35782
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 18s
Create tag and build when new code gets to main / Export (push) Successful in 9m48s
added enemy inputs as a resource
2026-01-16 11:18:57 +01:00

41 lines
917 B
C#

using Godot;
using System;
using Movementtests.player_controller.Scripts;
public partial class FirstEnemy : CharacterBody3D
{
[Export]
public Node3D Target { get; set; }
[Export]
public EnemyInitInputs Inputs;
private RayCast3D _wallInFrontRayCast;
public override void _Ready()
{
_wallInFrontRayCast = GetNode<RayCast3D>("WallInFrontRayCast");
}
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();
}
}