NPC angle lock when using weapon
parent
423c3e3b17
commit
9c763357b9
|
@ -159,6 +159,14 @@ namespace SupaLidlGame.Characters
|
|||
}
|
||||
}
|
||||
|
||||
public void LookTowardsDirection()
|
||||
{
|
||||
if (!Direction.IsZeroApprox())
|
||||
{
|
||||
Target = Direction;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void _on_hurtbox_received_damage(
|
||||
float damage,
|
||||
Character inflictor,
|
||||
|
|
|
@ -216,7 +216,7 @@ namespace SupaLidlGame.Characters
|
|||
float dist = GlobalPosition.DistanceSquaredTo(pos);
|
||||
UpdateWeights(pos);
|
||||
|
||||
if (Target.LengthSquared() < 1024)
|
||||
if (dist < 1024)
|
||||
{
|
||||
if (Inventory.SelectedItem is Weapon weapon)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=29 format=3 uid="uid://b2254pup8k161"]
|
||||
[gd_scene load_steps=30 format=3 uid="uid://b2254pup8k161"]
|
||||
|
||||
[ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"]
|
||||
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_ngsgt"]
|
||||
|
@ -11,6 +11,7 @@
|
|||
[ext_resource type="Script" path="res://Items/Inventory.cs" id="7_xyenu"]
|
||||
[ext_resource type="Script" path="res://State/Character/PlayerRollState.cs" id="8_fy0v5"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjgxyhgcyvsv7" path="res://BoundingBoxes/Hurtbox.tscn" id="9_avyu4"]
|
||||
[ext_resource type="PackedScene" uid="uid://g7wfcubs6bdd" path="res://Items/Weapons/Railgun.tscn" id="10_7kb8b"]
|
||||
[ext_resource type="AudioStream" uid="uid://njun3e6v4854" path="res://Assets/Sounds/hurt.wav" id="12_h0x0g"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h78y7"]
|
||||
|
@ -209,6 +210,8 @@ InventoryMap = {
|
|||
"equip_2": 1
|
||||
}
|
||||
|
||||
[node name="Railgun" parent="Inventory" instance=ExtResource("10_7kb8b")]
|
||||
|
||||
[node name="Node2D" parent="Inventory" instance=ExtResource("7_4rxuv")]
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource("9_avyu4")]
|
||||
|
|
|
@ -35,20 +35,31 @@ namespace SupaLidlGame.Items
|
|||
[Export]
|
||||
public float InitialVelocity { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Hides the weapon if it is idle (i.e. not being used).
|
||||
/// </summary>
|
||||
[Export]
|
||||
public bool ShouldHideIdle { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Freezes the player's target angle if this weapon is being used.
|
||||
/// </summary>
|
||||
[Export]
|
||||
public bool ShouldFreezeAngleOnUse { get; set; } = true;
|
||||
|
||||
[Export]
|
||||
public float MinDistanceHint { get; set; }
|
||||
|
||||
[Export]
|
||||
public float MaxDistanceHint { get; set; }
|
||||
|
||||
public virtual bool IsParryable { get; protected set; } = false;
|
||||
|
||||
public bool IsParried { get; set; }
|
||||
|
||||
public Character Character { get; set; }
|
||||
|
||||
[Export]
|
||||
public float MinDistanceHint { get; set; }
|
||||
|
||||
[Export]
|
||||
public float MaxDistanceHint { get; set; }
|
||||
public Vector2 UseDirection { get; set; }
|
||||
|
||||
public override bool StacksWith(Item item) => false;
|
||||
|
||||
|
|
|
@ -27,9 +27,10 @@ UseTime = 1.0
|
|||
script = ExtResource("1_xynim")
|
||||
InitialState = NodePath("Idle")
|
||||
|
||||
[node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("FireState")]
|
||||
[node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("FireState", "Weapon")]
|
||||
script = ExtResource("2_a4hhy")
|
||||
FireState = NodePath("../Fire")
|
||||
Weapon = NodePath("../..")
|
||||
|
||||
[node name="Fire" type="Node" parent="State" node_paths=PackedStringArray("Weapon", "IdleState")]
|
||||
script = ExtResource("3_dcbnq")
|
||||
|
|
|
@ -20,6 +20,27 @@ namespace SupaLidlGame.State.Character
|
|||
{
|
||||
Character.StunTime -= delta;
|
||||
}
|
||||
|
||||
var item = Character.Inventory.SelectedItem;
|
||||
var offhand = Character.Inventory.OffhandItem;
|
||||
|
||||
// angle towards item use angle or offhand use angle if not used
|
||||
|
||||
bool targetTowards(Items.Item item)
|
||||
{
|
||||
if (item is Items.Weapon weapon)
|
||||
{
|
||||
if (weapon.IsUsing)
|
||||
{
|
||||
Character.Target = weapon.UseDirection;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var _ = targetTowards(item) || targetTowards(offhand);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,47 +30,41 @@ namespace SupaLidlGame.State.Character
|
|||
{
|
||||
Character.Direction = Godot.Input.GetVector("ui_left", "ui_right",
|
||||
"ui_up", "ui_down");
|
||||
Character.LookTowardsDirection();
|
||||
|
||||
Vector2 mousePos = Character.GetGlobalMousePosition();
|
||||
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
|
||||
|
||||
bool faceToDir = !Character.Direction.IsZeroApprox();
|
||||
|
||||
bool targetTowards(Items.Item item)
|
||||
{
|
||||
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
|
||||
{
|
||||
if (!weapon.IsUsing)
|
||||
{
|
||||
if (weapon.ShouldHideIdle)
|
||||
{
|
||||
faceToDir = true;
|
||||
}
|
||||
else
|
||||
var isPressed = Godot.Input.IsActionPressed("attack1");
|
||||
var ret = false;
|
||||
|
||||
if (!weapon.ShouldHideIdle || isPressed)
|
||||
{
|
||||
Character.Target = dirToMouse;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
faceToDir = false;
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if (faceToDir)
|
||||
if (isPressed)
|
||||
{
|
||||
Character.Target = Character.Direction;
|
||||
}
|
||||
|
||||
if (Godot.Input.IsActionPressed("attack1"))
|
||||
{
|
||||
var item = Character.Inventory.SelectedItem;
|
||||
if (item is not null)
|
||||
{
|
||||
if (!item.IsUsing)
|
||||
{
|
||||
Character.Target = dirToMouse;
|
||||
}
|
||||
Character.UseCurrentItem();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var item = Character.Inventory.SelectedItem;
|
||||
var offhand = Character.Inventory.OffhandItem;
|
||||
|
||||
var _ = targetTowards(item) || targetTowards(offhand);
|
||||
|
||||
return base.Process(delta);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace SupaLidlGame.State.Weapon
|
|||
//_timeLeft
|
||||
_timeLeft = Weapon.UseTime;
|
||||
Weapon.Attack();
|
||||
Weapon.UseDirection = Weapon.Character.Target;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace SupaLidlGame.State.Weapon
|
|||
_attackAnimDuration = Sword.AttackAnimationDuration;
|
||||
|
||||
Sword.Visible = true;
|
||||
|
||||
Sword.UseDirection = Sword.Character.Target;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue