removing broken ABC and refactoring enemy movement
This commit is contained in:
@@ -123,7 +123,6 @@
|
||||
<Content Include="menus\scripts\level_state.gd.uid" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="ABCs\" />
|
||||
<Folder Include="addons\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
15
interfaces/IMoveable.cs
Normal file
15
interfaces/IMoveable.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Godot;
|
||||
|
||||
namespace Movementtests.interfaces;
|
||||
|
||||
public record MovementInputs(
|
||||
Vector3 Velocity = default,
|
||||
Vector3 TargetLocation = default,
|
||||
bool isOnFloor = false,
|
||||
Vector3 gravity = default,
|
||||
double delta = 0);
|
||||
|
||||
public interface IMoveable
|
||||
{
|
||||
Vector3 ComputeVelocity(MovementInputs inputs);
|
||||
}
|
||||
1
interfaces/IMoveable.cs.uid
Normal file
1
interfaces/IMoveable.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dp6v42a2iwlbs
|
||||
@@ -1,14 +1,10 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://q7uc1h2jpbd2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_62kkh"]
|
||||
[ext_resource type="Material" uid="uid://31aulub2nqov" path="res://assets/greybox/m_greybox.tres" id="2_3uydm"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="2_sysok"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxt0e2ugmttqq" path="res://scenes/enemies/first_enemy/first_enemy.tscn" id="3_3uydm"]
|
||||
[ext_resource type="Script" uid="uid://b2vdwkiqauhk3" path="res://scenes/enemies/first_enemy/EnemyInitInputs.cs" id="4_nd7vd"]
|
||||
[ext_resource type="PackedScene" uid="uid://cmlud1hwkd6sv" path="res://scenes/enemies/flying_enemy/flying_enemy.tscn" id="5_8fd2t"]
|
||||
[ext_resource type="Script" uid="uid://do0dic4r3ri0s" path="res://scenes/enemies/flying_enemy/FlyingEnemyInputs.cs" id="6_7m3bq"]
|
||||
[ext_resource type="Resource" uid="uid://otfc2snh8umc" path="res://scenes/enemies/first_enemy/first_enemy_damage.tres" id="6_dmw1t"]
|
||||
[ext_resource type="Resource" uid="uid://dgo65k2ceqfvy" path="res://scenes/enemies/flying_enemy/flying_enemy_damage.tres" id="9_gp7s3"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_gp7s3"]
|
||||
script = ExtResource("2_sysok")
|
||||
@@ -37,33 +33,6 @@ ssil_radius = 8.4
|
||||
sdfgi_use_occlusion = true
|
||||
glow_enabled = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_8fd2t"]
|
||||
script = ExtResource("4_nd7vd")
|
||||
Speed = 1.2
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_7m3bq"]
|
||||
script = ExtResource("4_nd7vd")
|
||||
Speed = 2.7
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_sysok"]
|
||||
script = ExtResource("4_nd7vd")
|
||||
Speed = 4.0
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_caohq"]
|
||||
script = ExtResource("6_7m3bq")
|
||||
Speed = 0.3
|
||||
TargetHeight = 10.0
|
||||
metadata/_custom_type_script = "uid://do0dic4r3ri0s"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_dmw1t"]
|
||||
script = ExtResource("6_7m3bq")
|
||||
Speed = 6.0
|
||||
TargetHeight = 15.0
|
||||
metadata/_custom_type_script = "uid://do0dic4r3ri0s"
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_62kkh")]
|
||||
@@ -134,29 +103,19 @@ material = ExtResource("2_3uydm")
|
||||
[node name="Enemy" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_8fd2t")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="Enemy2" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_7m3bq")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="Enemy3" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("3_3uydm")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.5, 0, -16.83681)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_sysok")
|
||||
GetDamageDealt = ExtResource("6_dmw1t")
|
||||
|
||||
[node name="FlyingEnemy" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 7, -16)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_caohq")
|
||||
GetDamageDealt = ExtResource("9_gp7s3")
|
||||
|
||||
[node name="FlyingEnemy2" parent="." node_paths=PackedStringArray("Target") instance=ExtResource("5_8fd2t")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 7, -16)
|
||||
Target = NodePath("../Player")
|
||||
Inputs = SubResource("Resource_dmw1t")
|
||||
GetDamageDealt = ExtResource("9_gp7s3")
|
||||
|
||||
@@ -33,8 +33,6 @@ public partial class PlayerController : CharacterBody3D, IDamageable, IKnockback
|
||||
// Signals and events //
|
||||
///////////////////////////
|
||||
|
||||
public event Action<float> DamageTaken;
|
||||
|
||||
///////////////////////////
|
||||
// Public stuff //
|
||||
///////////////////////////
|
||||
|
||||
23
resource_definitions/RMovement.cs
Normal file
23
resource_definitions/RMovement.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class RMovement : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed;
|
||||
|
||||
[Export(PropertyHint.Range, "0,20,1,or_greater")]
|
||||
public float TargetHeight;
|
||||
|
||||
public RMovement()
|
||||
{
|
||||
Speed = 3.0f;
|
||||
TargetHeight = 10.0f;
|
||||
}
|
||||
public RMovement(float speed, float targetHeight)
|
||||
{
|
||||
Speed = speed;
|
||||
TargetHeight = targetHeight;
|
||||
}
|
||||
}
|
||||
1
resource_definitions/RMovement.cs.uid
Normal file
1
resource_definitions/RMovement.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dtpxijlnb2c5
|
||||
@@ -1,79 +1,68 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FirstEnemy : CharacterBody3D, IDamageable, IDamageMaker, IHealthable, IKillable
|
||||
public partial class Enemy : CharacterBody3D, IDamageable, IDamageMaker, IHealthable, IKillable
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public EnemyInitInputs Inputs;
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
|
||||
[Export]
|
||||
public CHealth CHealth { get; set; }
|
||||
|
||||
[Export]
|
||||
public CDamageable CDamage { get; set; }
|
||||
|
||||
[Export]
|
||||
public Node CMovement { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDeathEffect[] DeathEffects { get; set; }
|
||||
|
||||
private RayCast3D _wallInFrontRayCast;
|
||||
private Area3D _damageBox;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_wallInFrontRayCast = GetNode<RayCast3D>("WallInFrontRayCast");
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
|
||||
CDamage.DamageTaken += ReduceHealth;
|
||||
CHealth.Dead += Kill;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var target = Target.GlobalPosition;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
var targetPlanar = new Vector3(Target.GlobalPosition.X, GlobalPosition.Y, Target.GlobalPosition.Z);
|
||||
LookAt(targetPlanar);
|
||||
|
||||
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
|
||||
LookAt(targetPlane);
|
||||
if (CMovement is not IMoveable movement) return;
|
||||
|
||||
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;
|
||||
var inputs = new MovementInputs(
|
||||
Velocity: Velocity,
|
||||
TargetLocation: Target.GlobalPosition,
|
||||
isOnFloor: IsOnFloor(),
|
||||
gravity: GetGravity(),
|
||||
delta: delta
|
||||
);
|
||||
Velocity = movement!.ComputeVelocity(inputs);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
GD.Print("Take this!");
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public float TakeDamage(RDamage damage)
|
||||
{
|
||||
GD.Print("Ouch!");
|
||||
return CDamage.TakeDamage(damage);
|
||||
}
|
||||
|
||||
public float CurrentHealth
|
||||
{
|
||||
get => CHealth.CurrentHealth;
|
||||
set => CHealth.CurrentHealth = value;
|
||||
}
|
||||
|
||||
public void ReduceHealth(float amount)
|
||||
{
|
||||
CHealth.ReduceHealth(amount);
|
||||
@@ -1,18 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class EnemyInitInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed;
|
||||
|
||||
public EnemyInitInputs()
|
||||
{
|
||||
Speed = 5.0f;
|
||||
}
|
||||
public EnemyInitInputs(float speed)
|
||||
{
|
||||
Speed = speed;
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://b2vdwkiqauhk3
|
||||
@@ -1,26 +1,13 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://dxt0e2ugmttqq"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://dxt0e2ugmttqq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/first_enemy/FirstEnemy.cs" id="1_4yfjf"]
|
||||
[ext_resource type="Script" uid="uid://b2vdwkiqauhk3" path="res://scenes/enemies/first_enemy/EnemyInitInputs.cs" id="2_42xu3"]
|
||||
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/Enemy.cs" id="1_r6506"]
|
||||
[ext_resource type="Resource" uid="uid://otfc2snh8umc" path="res://scenes/enemies/first_enemy/first_enemy_damage.tres" id="2_6d4gl"]
|
||||
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/health/CHealth.cs" id="2_gsmti"]
|
||||
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://resource_definitions/RDamageModifier.cs" id="2_r3cnf"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="3_1tw73"]
|
||||
[ext_resource type="Script" uid="uid://b4cwruitopcee" path="res://resource_definitions/RDeathEffect.cs" id="3_onjoj"]
|
||||
[ext_resource type="Script" uid="uid://baiapod3csndf" path="res://resource_definitions/RHealth.cs" id="3_pvbr4"]
|
||||
[ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://scenes/damage/CDamageable.cs" id="7_1tw73"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_66m7n"]
|
||||
script = ExtResource("2_42xu3")
|
||||
Speed = 2.0
|
||||
metadata/_custom_type_script = "uid://b2vdwkiqauhk3"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_a6xb8"]
|
||||
script = ExtResource("3_1tw73")
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_7gyf3"]
|
||||
script = ExtResource("3_onjoj")
|
||||
metadata/_custom_type_script = "uid://b4cwruitopcee"
|
||||
[ext_resource type="PackedScene" uid="uid://dbr7ioio158ew" path="res://scenes/movement/CGroundedMovement.tscn" id="7_qyswd"]
|
||||
[ext_resource type="Script" uid="uid://dtpxijlnb2c5" path="res://resource_definitions/RMovement.cs" id="8_6d4gl"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_r3cnf"]
|
||||
script = ExtResource("3_pvbr4")
|
||||
@@ -30,6 +17,11 @@ metadata/_custom_type_script = "uid://baiapod3csndf"
|
||||
script = ExtResource("2_r3cnf")
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_s01ng"]
|
||||
script = ExtResource("8_6d4gl")
|
||||
Speed = 3.0
|
||||
metadata/_custom_type_script = "uid://dtpxijlnb2c5"
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_62kkh"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_3uydm"]
|
||||
@@ -46,15 +38,15 @@ albedo_color = Color(0.06469653, 0.06469653, 0.06469653, 1)
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4yfjf"]
|
||||
size = Vector3(1, 2, 2)
|
||||
|
||||
[node name="FirstEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage")]
|
||||
[node name="FirstEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage", "CMovement")]
|
||||
collision_layer = 16
|
||||
collision_mask = 273
|
||||
script = ExtResource("1_4yfjf")
|
||||
Inputs = SubResource("Resource_66m7n")
|
||||
GetDamageDealt = SubResource("Resource_a6xb8")
|
||||
script = ExtResource("1_r6506")
|
||||
GetDamageDealt = ExtResource("2_6d4gl")
|
||||
CHealth = NodePath("CHealth")
|
||||
CDamage = NodePath("CDamageable")
|
||||
DeathEffects = Array[Object]([SubResource("Resource_7gyf3")])
|
||||
CMovement = NodePath("CGroundedMovement")
|
||||
DeathEffects = Array[Object]([])
|
||||
|
||||
[node name="CHealth" type="Node" parent="."]
|
||||
script = ExtResource("2_gsmti")
|
||||
@@ -66,6 +58,10 @@ script = ExtResource("7_1tw73")
|
||||
DamageModifiers = Array[Object]([SubResource("Resource_qj0ob")])
|
||||
metadata/_custom_type_script = "uid://b0u23nkpaimyc"
|
||||
|
||||
[node name="CGroundedMovement" parent="." node_paths=PackedStringArray("WallInFrontRayCast") instance=ExtResource("7_qyswd")]
|
||||
RMovement = SubResource("Resource_s01ng")
|
||||
WallInFrontRayCast = NodePath("../WallInFrontRayCast")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = SubResource("CapsuleShape3D_62kkh")
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IHealthable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public FlyingEnemyInputs Inputs { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
[Export]
|
||||
public CHealth CHealth { get; set; }
|
||||
[Export]
|
||||
public CDamageable CDamage { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDeathEffect[] DeathEffects { get; set; }
|
||||
|
||||
private RayCast3D _groundDistanceRaycast;
|
||||
private Area3D _damageBox;
|
||||
|
||||
private bool _movingToDesiredHeight = true;
|
||||
private Vector3 _randomDirection;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_groundDistanceRaycast = GetNode<RayCast3D>("GroundDistance");
|
||||
_groundDistanceRaycast.TargetPosition = new Vector3(0, 0, 0);
|
||||
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
|
||||
CDamage.DamageTaken += ReduceHealth;
|
||||
CHealth.Dead += Kill;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var target = Target.GlobalPosition;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
Vector3 velocity = Velocity;
|
||||
|
||||
LookAt(target);
|
||||
|
||||
// Check if we have a direct line of sight to the player
|
||||
if (!_movingToDesiredHeight)
|
||||
{
|
||||
velocity = direction * Inputs.Speed;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
_movingToDesiredHeight = true;
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = _randomDirection * Inputs.Speed;
|
||||
|
||||
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*Inputs.TargetHeight, _groundDistanceRaycast.CollisionMask);
|
||||
var groundResult = spaceState.IntersectRay(groundQuery);
|
||||
if (groundResult.Count == 0)
|
||||
{
|
||||
velocity.Y = 0;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count == 0)
|
||||
{
|
||||
_movingToDesiredHeight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public event Action<float> DamageTaken;
|
||||
|
||||
|
||||
public float TakeDamage(RDamage damage)
|
||||
{
|
||||
return CDamage.TakeDamage(damage);
|
||||
}
|
||||
|
||||
public void ReduceHealth(float amount)
|
||||
{
|
||||
CHealth.ReduceHealth(amount);
|
||||
}
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
foreach (var killable in DeathEffects.ToIKillables())
|
||||
{
|
||||
killable.Kill();
|
||||
}
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://cmvep0qi7qlvf
|
||||
@@ -1,23 +0,0 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FlyingEnemyInputs : Resource
|
||||
{
|
||||
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
|
||||
public float Speed;
|
||||
|
||||
[Export(PropertyHint.Range, "0,100,1,or_greater")]
|
||||
public float TargetHeight;
|
||||
|
||||
public FlyingEnemyInputs()
|
||||
{
|
||||
Speed = 5.0f;
|
||||
TargetHeight = 50.0f;
|
||||
}
|
||||
public FlyingEnemyInputs(float speed, float targetHeight)
|
||||
{
|
||||
Speed = speed;
|
||||
TargetHeight = targetHeight;
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://do0dic4r3ri0s
|
||||
@@ -1,30 +1,14 @@
|
||||
[gd_scene load_steps=20 format=3 uid="uid://cmlud1hwkd6sv"]
|
||||
[gd_scene load_steps=18 format=3 uid="uid://cmlud1hwkd6sv"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cmvep0qi7qlvf" path="res://scenes/enemies/flying_enemy/FlyingEnemy.cs" id="1_b46rq"]
|
||||
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/Enemy.cs" id="1_q8l7o"]
|
||||
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://resource_definitions/RDamageModifier.cs" id="2_1bsgx"]
|
||||
[ext_resource type="Script" uid="uid://do0dic4r3ri0s" path="res://scenes/enemies/flying_enemy/FlyingEnemyInputs.cs" id="2_aarbi"]
|
||||
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="2_irbqc"]
|
||||
[ext_resource type="Script" uid="uid://b4cwruitopcee" path="res://resource_definitions/RDeathEffect.cs" id="4_12h4s"]
|
||||
[ext_resource type="Resource" uid="uid://dgo65k2ceqfvy" path="res://scenes/enemies/flying_enemy/flying_enemy_damage.tres" id="2_on7rt"]
|
||||
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/health/CHealth.cs" id="4_ys4jv"]
|
||||
[ext_resource type="Script" uid="uid://baiapod3csndf" path="res://resource_definitions/RHealth.cs" id="5_irbqc"]
|
||||
[ext_resource type="PackedScene" uid="uid://dmw5ibwrb483f" path="res://scenes/movement/CFlyingMovement.tscn" id="7_vaeds"]
|
||||
[ext_resource type="Script" uid="uid://dtpxijlnb2c5" path="res://resource_definitions/RMovement.cs" id="8_on7rt"]
|
||||
[ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://scenes/damage/CDamageable.cs" id="8_uotso"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_7nxyi"]
|
||||
script = ExtResource("2_aarbi")
|
||||
Speed = 5.0
|
||||
TargetHeight = 10.0
|
||||
metadata/_custom_type_script = "uid://do0dic4r3ri0s"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_o3msb"]
|
||||
script = ExtResource("2_irbqc")
|
||||
DamageDealt = 2.0
|
||||
DamageType = 2
|
||||
metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ys4jv"]
|
||||
script = ExtResource("4_12h4s")
|
||||
metadata/_custom_type_script = "uid://b4cwruitopcee"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_aarbi"]
|
||||
script = ExtResource("5_irbqc")
|
||||
StartingHealth = 50.0
|
||||
@@ -39,6 +23,12 @@ script = ExtResource("2_1bsgx")
|
||||
DamageType = 1
|
||||
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ma2bq"]
|
||||
script = ExtResource("8_on7rt")
|
||||
Speed = 2.0
|
||||
TargetHeight = 10.0
|
||||
metadata/_custom_type_script = "uid://dtpxijlnb2c5"
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_b46rq"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_1bsgx"]
|
||||
@@ -55,16 +45,16 @@ albedo_color = Color(0.06469653, 0.06469653, 0.06469653, 1)
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4yfjf"]
|
||||
size = Vector3(1, 1, 1.5)
|
||||
|
||||
[node name="FlyingEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage")]
|
||||
[node name="FlyingEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage", "CMovement")]
|
||||
collision_layer = 16
|
||||
collision_mask = 273
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_b46rq")
|
||||
Inputs = SubResource("Resource_7nxyi")
|
||||
GetDamageDealt = SubResource("Resource_o3msb")
|
||||
script = ExtResource("1_q8l7o")
|
||||
GetDamageDealt = ExtResource("2_on7rt")
|
||||
CHealth = NodePath("CHealth")
|
||||
CDamage = NodePath("CDamageable")
|
||||
DeathEffects = Array[Object]([SubResource("Resource_ys4jv")])
|
||||
CMovement = NodePath("CFlyingMovement")
|
||||
DeathEffects = Array[Object]([])
|
||||
|
||||
[node name="CHealth" type="Node" parent="."]
|
||||
script = ExtResource("4_ys4jv")
|
||||
@@ -76,6 +66,10 @@ script = ExtResource("8_uotso")
|
||||
DamageModifiers = Array[Object]([SubResource("Resource_jnv07"), SubResource("Resource_53j1c")])
|
||||
metadata/_custom_type_script = "uid://b0u23nkpaimyc"
|
||||
|
||||
[node name="CFlyingMovement" parent="." instance=ExtResource("7_vaeds")]
|
||||
RMovement = SubResource("Resource_ma2bq")
|
||||
TerrainCollision = 256
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_b46rq")
|
||||
|
||||
|
||||
62
scenes/movement/CFlyingMovement.cs
Normal file
62
scenes/movement/CFlyingMovement.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
namespace Movementtests.scenes.movement;
|
||||
|
||||
public partial class CFlyingMovement : Node3D, IMoveable
|
||||
{
|
||||
[Export] public RMovement RMovement;
|
||||
|
||||
[Export(PropertyHint.Layers3DPhysics)]
|
||||
public uint TerrainCollision { get; set; } = 1;
|
||||
|
||||
private bool _movingToDesiredHeight = true;
|
||||
private Vector3 _randomDirection;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
|
||||
public new Vector3 ComputeVelocity(MovementInputs inputs)
|
||||
{
|
||||
var velocity = inputs.Velocity;
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var target = inputs.TargetLocation;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
// Check if we have a direct line of sight to the player
|
||||
if (!_movingToDesiredHeight)
|
||||
{
|
||||
velocity = direction * RMovement.Speed;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, TerrainCollision);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
_movingToDesiredHeight = true;
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = _randomDirection * RMovement.Speed;
|
||||
|
||||
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*RMovement.TargetHeight, TerrainCollision);
|
||||
var groundResult = spaceState.IntersectRay(groundQuery);
|
||||
if (groundResult.Count == 0)
|
||||
{
|
||||
velocity.Y = 0;
|
||||
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, TerrainCollision);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count == 0)
|
||||
{
|
||||
_movingToDesiredHeight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
}
|
||||
1
scenes/movement/CFlyingMovement.cs.uid
Normal file
1
scenes/movement/CFlyingMovement.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cps1rbkxs3nvq
|
||||
7
scenes/movement/CFlyingMovement.tscn
Normal file
7
scenes/movement/CFlyingMovement.tscn
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dmw5ibwrb483f"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cps1rbkxs3nvq" path="res://scenes/movement/CFlyingMovement.cs" id="1_i26q2"]
|
||||
|
||||
[node name="CFlyingMovement" type="Node3D"]
|
||||
script = ExtResource("1_i26q2")
|
||||
CollisionMask = 256
|
||||
33
scenes/movement/CGroundedMovement.cs
Normal file
33
scenes/movement/CGroundedMovement.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
namespace Movementtests.scenes.movement;
|
||||
|
||||
public partial class CGroundedMovement : Node3D, IMoveable
|
||||
{
|
||||
[Export] public RMovement RMovement;
|
||||
|
||||
[Export]
|
||||
public RayCast3D WallInFrontRayCast { get; set; }
|
||||
|
||||
|
||||
public new Vector3 ComputeVelocity(MovementInputs inputs)
|
||||
{
|
||||
var velocity = inputs.Velocity;
|
||||
var target = inputs.TargetLocation;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
|
||||
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
|
||||
LookAt(targetPlane);
|
||||
|
||||
velocity.X = direction.X * RMovement.Speed;
|
||||
velocity.Z = direction.Z * RMovement.Speed;
|
||||
|
||||
if (WallInFrontRayCast.IsColliding())
|
||||
velocity.Y = RMovement.Speed;
|
||||
else if (!inputs.isOnFloor)
|
||||
velocity += inputs.gravity * (float)inputs.delta;
|
||||
|
||||
return velocity;
|
||||
}
|
||||
}
|
||||
1
scenes/movement/CGroundedMovement.cs.uid
Normal file
1
scenes/movement/CGroundedMovement.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bdag2eeixw2lt
|
||||
6
scenes/movement/CGroundedMovement.tscn
Normal file
6
scenes/movement/CGroundedMovement.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dbr7ioio158ew"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bdag2eeixw2lt" path="res://scenes/movement/CGroundedMovement.cs" id="1_e0agf"]
|
||||
|
||||
[node name="CGroundedMovement" type="Node3D"]
|
||||
script = ExtResource("1_e0agf")
|
||||
@@ -37,10 +37,10 @@ public partial class Spawner : Node3D
|
||||
{
|
||||
if (SceneToSpawn == null || !SceneToSpawn.CanInstantiate()) return;
|
||||
|
||||
var spawnedInstance = SceneToSpawn.Instantiate() as FirstEnemy;
|
||||
var spawnedInstance = SceneToSpawn.Instantiate() as Enemy;
|
||||
if (spawnedInstance == null) return;
|
||||
|
||||
spawnedInstance.Inputs = Inputs as EnemyInitInputs;
|
||||
// spawnedInstance.Inputs = Inputs as EnemyInitInputs;
|
||||
spawnedInstance.Target = Target;
|
||||
GetTree().GetCurrentScene().AddChild(spawnedInstance);
|
||||
spawnedInstance.GlobalPosition = GlobalPosition;
|
||||
|
||||
Reference in New Issue
Block a user