Files
MovementTests/scenes/enemies/FirstEnemy.cs
Minimata 9e75193731
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 20s
Create tag and build when new code gets to main / Export (push) Successful in 10m18s
enemies can move, also changed and named a few collision layers
2026-01-16 11:05:02 +01:00

41 lines
935 B
C#

using Godot;
using System;
using Movementtests.player_controller.Scripts;
public partial class FirstEnemy : CharacterBody3D
{
[Export]
public Node3D Target { get; set; }
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
public float Speed = 5.0f;
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 * Speed;
velocity.Z = direction.Z * Speed;
if (_wallInFrontRayCast.IsColliding())
velocity.Y = Speed;
else if (!IsOnFloor())
velocity += GetGravity() * (float)delta;
Velocity = velocity;
MoveAndSlide();
}
}