added enemy inputs as a resource
This commit is contained in:
18
scenes/enemies/EnemyInitInputs.cs
Normal file
18
scenes/enemies/EnemyInitInputs.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class EnemyInitInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed = 5.0f;
|
||||
|
||||
public EnemyInitInputs()
|
||||
{
|
||||
Speed = 5.0f;
|
||||
}
|
||||
public EnemyInitInputs(float speed)
|
||||
{
|
||||
Speed = speed;
|
||||
}
|
||||
}
|
||||
1
scenes/enemies/EnemyInitInputs.cs.uid
Normal file
1
scenes/enemies/EnemyInitInputs.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b2vdwkiqauhk3
|
||||
@@ -7,8 +7,8 @@ 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;
|
||||
[Export]
|
||||
public EnemyInitInputs Inputs;
|
||||
|
||||
private RayCast3D _wallInFrontRayCast;
|
||||
|
||||
@@ -26,11 +26,11 @@ public partial class FirstEnemy : CharacterBody3D
|
||||
LookAt(targetPlane);
|
||||
|
||||
var velocity = Velocity;
|
||||
velocity.X = direction.X * Speed;
|
||||
velocity.Z = direction.Z * Speed;
|
||||
velocity.X = direction.X * Inputs.Speed;
|
||||
velocity.Z = direction.Z * Inputs.Speed;
|
||||
|
||||
if (_wallInFrontRayCast.IsColliding())
|
||||
velocity.Y = Speed;
|
||||
velocity.Y = Inputs.Speed;
|
||||
else if (!IsOnFloor())
|
||||
velocity += GetGravity() * (float)delta;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user