stunnable targets on hit

This commit is contained in:
2026-05-15 15:29:24 +02:00
parent a0e99a959f
commit afa335e7bf
19 changed files with 200 additions and 60 deletions

View File

@@ -21,6 +21,8 @@ public partial class CFlyingMovement : Node3D, IMoveable
public Vector3 ComputeVelocity(MovementInputs inputs)
{
if (inputs.IsStunned) return inputs.Velocity.Lerp(Vector3.Zero, (float) inputs.Delta * RMovement.Acceleration);
var velocity = inputs.Velocity;
var spaceState = GetWorld3D().DirectSpaceState;
var target = inputs.TargetLocation;
@@ -28,7 +30,7 @@ public partial class CFlyingMovement : Node3D, IMoveable
// Check if we have a direct line of sight to the player
if (!_movingToDesiredHeight)
{
velocity = velocity.Lerp(direction * RMovement.Speed, (float) inputs.delta * RMovement.Acceleration);
velocity = velocity.Lerp(direction * RMovement.Speed, (float) inputs.Delta * RMovement.Acceleration);
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, TerrainCollision);
var result = spaceState.IntersectRay(query);
@@ -40,7 +42,7 @@ public partial class CFlyingMovement : Node3D, IMoveable
}
else
{
velocity = velocity.Lerp(_randomDirection * RMovement.Speed, (float) inputs.delta * RMovement.Acceleration);
velocity = velocity.Lerp(_randomDirection * RMovement.Speed, (float) inputs.Delta * RMovement.Acceleration);
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*RMovement.TargetHeight, TerrainCollision);
var groundResult = spaceState.IntersectRay(groundQuery);

View File

@@ -19,15 +19,18 @@ public partial class CGroundedMovement : Node3D, IMoveable
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
LookAt(targetPlane);
float xAcc = (float) Mathf.Lerp(velocity.X, direction.X * RMovement.Speed, inputs.delta * RMovement.Acceleration);
float zAcc = (float) Mathf.Lerp(velocity.Z, direction.Z * RMovement.Speed, inputs.delta * RMovement.Acceleration);
var targetXSpeed = inputs.IsStunned ? 0 : direction.X * RMovement.Speed;
var targetZSpeed = inputs.IsStunned ? 0 : direction.Z * RMovement.Speed;
float xAcc = (float) Mathf.Lerp(velocity.X, targetXSpeed, inputs.Delta * RMovement.Acceleration);
float zAcc = (float) Mathf.Lerp(velocity.Z, targetZSpeed, inputs.Delta * RMovement.Acceleration);
velocity.X = xAcc;
velocity.Z = zAcc;
if (WallInFrontRayCast.IsColliding())
if (WallInFrontRayCast.IsColliding() && !inputs.IsStunned)
velocity.Y = RMovement.Speed;
else if (!inputs.isOnFloor)
velocity += inputs.gravity * (float)inputs.delta * RMovement.GravityModifier;
else if (!inputs.IsOnFloor)
velocity += inputs.Gravity * (float)inputs.Delta * RMovement.GravityModifier;
return velocity;
}

View File

@@ -130,11 +130,16 @@ public partial class Enemy : CharacterBody3D,
Events.Subscribe<KnockbackDone>(Tag.RequestTag(TagsManager, "events.combat.knockback_received"), OnKnockbackReceived);
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.death"), OnDeath);
Events.Subscribe(Tag.RequestTag(TagsManager, "events.enemy.request_projectile"), ProjectileTokenRequested);
}
private bool IsStunned()
{
return Tags.CombinedTags.HasTag(Tag.RequestTag(TagsManager, "status.stunned"));
}
private void ProjectileTokenRequested(EventData obj)
{
if (IsStunned()) return;
// TODO: replace with token manager
Events.Raise(new EventData<OnProjectileSpawned>
{
@@ -154,24 +159,34 @@ public partial class Enemy : CharacterBody3D,
{
// Only trigger gameplay-related effects on specific frames
if(Engine.GetPhysicsFrames() % 10 == 0) ProcessGameplay(delta);
var targetPlanar = new Vector3(Target.GlobalPosition.X, GlobalPosition.Y, Target.GlobalPosition.Z);
LookAt(targetPlanar);
if (!IsStunned())
{
var targetPlanar = new Vector3(Target.GlobalPosition.X, GlobalPosition.Y, Target.GlobalPosition.Z);
LookAt(targetPlanar);
}
var inputs = new MovementInputs(
Velocity: Velocity,
TargetLocation: Target.GlobalPosition,
isOnFloor: IsOnFloor(),
gravity: GetGravity(),
delta: delta
IsOnFloor: IsOnFloor(),
IsStunned: IsStunned(),
Gravity: GetGravity(),
Delta: delta
);
Velocity = ComputeVelocity(inputs);
Velocity += ComputeKnockback();
MoveAndSlide();
}
public void ProcessGameplay(double delta)
{
if (IsStunned())
{
GD.Print("Cannot attack, stunned!");
return;
}
// if (_hitAbilityHandle == null) return;
var bodies = DamageBox.GetOverlappingBodies();

View File

@@ -64,7 +64,7 @@ InitialStack = SubResource("Resource_8x1id")
Cues = []
metadata/_custom_type_script = "uid://b83hf13nj37k3"
[sub_resource type="ViewportTexture" id="ViewportTexture_4oy82"]
[sub_resource type="ViewportTexture" id="ViewportTexture_46wn3"]
viewport_path = NodePath("SubViewport")
[sub_resource type="Resource" id="Resource_on7rt"]
@@ -141,7 +141,7 @@ metadata/_custom_type_script = "uid://dps0oef50noil"
[node name="CHealthBar" parent="." unique_id=1635725931 instance=ExtResource("7_ykkxn")]
transform = Transform3D(0.3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.70000005, 0)
texture = SubResource("ViewportTexture_4oy82")
texture = SubResource("ViewportTexture_46wn3")
[node name="CMovement" parent="." unique_id=1699571730 instance=ExtResource("7_vaeds")]
RMovement = SubResource("Resource_on7rt")

View File

@@ -141,7 +141,7 @@ InitialStack = SubResource("Resource_hgi6f")
Cues = []
metadata/_custom_type_script = "uid://b83hf13nj37k3"
[sub_resource type="ViewportTexture" id="ViewportTexture_xabdf"]
[sub_resource type="ViewportTexture" id="ViewportTexture_rlvdp"]
viewport_path = NodePath("SubViewport")
[sub_resource type="Resource" id="Resource_6d4gl"]
@@ -177,7 +177,6 @@ collision_layer = 16
collision_mask = 273
script = ExtResource("1_ha67n")
EnemyHeight = 2.0
LaunchProjectileAbility = ExtResource("2_rlvdp")
RKnockback = ExtResource("3_ymgar")
RMovement = ExtResource("4_0f52b")
@@ -222,7 +221,7 @@ metadata/_custom_type_script = "uid://dps0oef50noil"
[node name="CHealthBar" parent="." unique_id=1278247727 instance=ExtResource("9_6ew2r")]
transform = Transform3D(0.4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.2, 0)
texture = SubResource("ViewportTexture_xabdf")
texture = SubResource("ViewportTexture_rlvdp")
[node name="CMovement" parent="." unique_id=1080640834 node_paths=PackedStringArray("WallInFrontRayCast") instance=ExtResource("10_d3cra")]
RMovement = SubResource("Resource_6d4gl")

View File

@@ -89,7 +89,7 @@ metadata/_custom_type_script = "uid://dpakv7agvir6y"
[sub_resource type="Resource" id="Resource_cmmfb"]
script = ExtResource("10_b0xmb")
Name = "Parry projectile"
CooldownEffects = null
CooldownEffects = []
AbilityBehavior = SubResource("Resource_xs7wf")
TriggerSource = 1
TriggerTag = SubResource("Resource_cm4e8")

View File

@@ -2467,7 +2467,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
// else HeadSystem.OnHit();
// var streamName = isParry ? "parry" : "attacks";
_audioStream.SwitchToClipByName("dash");
IsInvincible = true;
OnHitInvincibility();
var plannedDashLocation = _targetLocation + Vector3.Down*_playerHeight/2;
// var enemySurfaceQuery = PhysicsRayQueryParameters3D.Create(HeadSystem.GlobalPosition, plannedDashLocation, DashSystem.DashCast3D.CollisionMask);
@@ -2511,7 +2511,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
{
disableable.Disable();
}
IsInvincible = false;
// IsInvincible = false;
_playerState.SendEvent("attack_finished");
}