enemies can move, also changed and named a few collision layers
This commit is contained in:
40
scenes/enemies/FirstEnemy.cs
Normal file
40
scenes/enemies/FirstEnemy.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user