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("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(); } }